none
Cannot open database "AdventureWorksLT" requested by the login. The login failed. Login failed for user ;SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Question

  • I am using windows xp, visual studio2008, and sqlexpress.  Using the following connection string I get the following error:

    string connectionString =
              "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorksLT;Integrated Security=True";

    "
    Server Error in '/WebSite8' Application.
    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Source Error:

    Line 20:         DataSet dataSet = new DataSet();
    Line 21:         // 4. fill the dataset object        
    Line 22:         dataAdapter.Fill(dataSet, "Customers");
    Line 23:
    Line 24:         // 5. Get the table from the dataset        


    Source File: c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\WebSites\WebSite8\SimpleADONetGridView.aspx.cs    Line: 22

    Stack Trace:

    [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
       System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4860189
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
       System.Data.SqlClient.SqlConnection.Open() +122
       System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +31
       System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +112
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
       SimpleADONetGridView.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\WebSites\WebSite8\SimpleADONetGridView.aspx.cs:22
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    I have followed instructions to change settings to local system rather than network, checked whether the server can accept remote connections, tcp/ip, and i have created exceptions for the sql server and sql browser on my firewall.

    Thanks in advance for your help.
    • Edited by budoman90 Wednesday, February 03, 2010 12:42 AM
    Wednesday, February 03, 2010 12:26 AM

Answers

  • Hi Budoman90,

    Have you tried connecting to Database from SQl Server Management Studio?

    I have found something similar from another post - See below


    It looks like you've set up your connection to use your Windows account to connect to the database rather than supplying a user name and password.  When you're connecting through Visual Web Developer at design-time, you're connecting to the database as yourself.  I'm guessing that you're an administrator on the machine and for the database and you connect successfully.  The actual application will run under the ASP.NET account.  If you have not granted that account permission to the database, the connection attempt will fail with the message you described.

    Here's a quick breakdown of some options:

    1.)  Use a user name and password in the connection string
    2.)  Have the application run under a different account that has permission to access the database
    3.)  Grant permission to the ASP.NET account
    4.)  Consider having ASP.NET impersonate the current user

    I hope this information proves helpful

    Thanks
    Vishal
    Wednesday, February 03, 2010 10:47 AM

All replies

  • For the error cannot open database "AdventureworksLT" requested by the login

     

    Use the link http://blog.sqlauthority.com/2009/08/20/sql-server-fix-error-cannot-open-database-requested-by-the-login-the-login-failed-login-failed-for-user-nt-authoritynetwork-service/ and fix your problem.

     

    The problem can be fixed by adding the windows login as a user in the adventureworksLT database.


    USE MASTER

    GO

    EXEC sp_grantlogin 'domainname\accountname' 

    GO

    USE yourDatabase 

    GO

    EXEC sp_grantdbaccess 'domainname\accountname' 



    Thanks, Leks
    Wednesday, February 03, 2010 12:36 AM
  • Thanks for your response Leks. I am using windows xp and have no sql server gui. I only have sql server configuration manager. So how do I do this on windows xp sql server configuration manager?


    Wednesday, February 03, 2010 4:19 AM
  • You must have tools like SSMS , SQLCMD or OSQL to run this on the database engine.

    Thanks, Leks
    Wednesday, February 03, 2010 5:36 AM
  • Hi Leks:

    I downloaded Microsoft SQL Server Management Studio Express, and followed the instructions on SQL Authority http://blog.sqlauthority.com/2009/08/20/sql-server-fix-error-cannot-open-database-requested-by-the-login-the-login-failed-login-failed-for-user-nt-authoritynetwork-service/ . I rebooted my machine several times.

    I am still getting the error message:

    Cannot open database "AdventureWorksLT" requested by the login. The login failed.
    Login failed for user 'OWNER-8C13F024F\Owner'.



    Thanks for your continued help.

    Regards,
    budoman90
    Wednesday, February 03, 2010 10:28 AM
  • Hi Budoman90,

    Have you tried connecting to Database from SQl Server Management Studio?

    I have found something similar from another post - See below


    It looks like you've set up your connection to use your Windows account to connect to the database rather than supplying a user name and password.  When you're connecting through Visual Web Developer at design-time, you're connecting to the database as yourself.  I'm guessing that you're an administrator on the machine and for the database and you connect successfully.  The actual application will run under the ASP.NET account.  If you have not granted that account permission to the database, the connection attempt will fail with the message you described.

    Here's a quick breakdown of some options:

    1.)  Use a user name and password in the connection string
    2.)  Have the application run under a different account that has permission to access the database
    3.)  Grant permission to the ASP.NET account
    4.)  Consider having ASP.NET impersonate the current user

    I hope this information proves helpful

    Thanks
    Vishal
    Wednesday, February 03, 2010 10:47 AM
  • Thanks Vishal! I will work on it later today. It is 4:05 in the am here in California.

    Wednesday, February 03, 2010 12:04 PM
  • Hi Vishal:

    Yes, I have connected to the database from MSQL Server Management Studio Express.

    Do you have an example of using the username and password in the connection string? I will try that first. If you have any urls for the 4 options listed above, that would be great.

    Thanks.

    Regards,
    budoman90
    Wednesday, February 03, 2010 5:33 PM
  • Here is what I use for reference http://www.connectionstrings.com/
    Wednesday, February 03, 2010 5:36 PM
  • Hi Vishal:

    I changed the connection string to include user and password as per the connection string website and I received the following error message:

     Login failed for user 'OWNER-8C13F024F\Owner'. The user is not associated with a trusted SQL Server connection.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'OWNER-8C13F024F\Owner'. The user is not associated with a trusted SQL Server connection.

    Source Error:

    Line 20:         DataSet dataSet = new DataSet();
    Line 21:         // 4. fill the dataset object        
    Line 22:         dataAdapter.Fill(dataSet, "Customers");
    Line 23:
    Line 24:         // 5. Get the table from the dataset        


    Source File: c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\WebSites\WebSite8\SimpleADONetGridView.aspx.cs    Line: 22

    Stack Trace:

    [SqlException (0x80131904): Login failed for user 'OWNER-8C13F024F\Owner'. The user is not associated with a trusted SQL Server connection.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +342
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
       System.Data.SqlClient.SqlConnection.Open() +122
       System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +31
       System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +112
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
       SimpleADONetGridView.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Owner\My Documents\Visual Studio 2008\WebSites\WebSite8\SimpleADONetGridView.aspx.cs:22
       System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
       System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
       System.Web.UI.Control.OnLoad(EventArgs e) +99
       System.Web.UI.Control.LoadRecursive() +50
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627



    Wednesday, February 03, 2010 6:15 PM
  • According to below you are passing windows user name and password in connection string and that is going to fail because you cant pass that via connection string. Try passing SQL username and password via connection string and make sure that SQL user have permission to connect database.





    Login failed for user 'OWNER-8C13F024F\Owner'. The user is not associated with a trusted SQL Server connection.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


    Wednesday, February 03, 2010 6:19 PM
  • Hi Vishal:

    I am still having problems trying to connect. I have tried various connection strings and I am still not able to connect. In addition, I have attempted to work with adding the user to the admin group through IIS, changed the properties in the webconfig file all to no avail.

    I am at a loss here. I am hoping for more help here.

    Thanks.
    Thursday, February 11, 2010 6:24 AM