Connecting to an SQL Database.

Discussion in 'Website Development & Design' started by Boby Smith, Jun 12, 2013.

  1. Boby Smith

    Boby Smith
    uix_expand uix_collapse
    Member

    Joined:
    Dec 15, 2011
    Messages:
    30
    Likes Received:
    2
    I am using C#.Net-VS2012 and SQL2008R2.
    My Computer Network name is b-pc, The Connection is Softguard.

    I have the following code snippet:-


    SqlConnection myConnection = new SqlConnection("server=b-pc\\Softguard;"+
    "database=SgTextiles; " +
    "connection timeout=5");
    myConnection.Open();


    It excepts with the following reason:

    System.Data.SqlClient.SqlException (0x80131904): Login failed for user ''.
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
    at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
    at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
    .....And Much More!!

    It seems to look for some form of authorisation.No username or password was provided (nor asked for) when the connection was created new in DbExplorer. Widows Authorisation was used at the time.

    By Jack Smith
     
  2. zeropid

    zeropid
    uix_expand uix_collapse
    Member

    Joined:
    Oct 24, 2011
    Messages:
    392
    Likes Received:
    12
    You should create user with this name and pwd and authorise remote connection for it
     

Share This Page