locked
Cannot open database "testDB" requested by the login. The login failed. RRS feed

  • Question

  • User357320440 posted

    Hi - I am deploying an asp.net site for the first time so please go easy...

    Am trying to run an asp.net 4.0 application on a Windows XP pro machine as a small intranet around an office network.  I've got it working ok throughout our network with IIS and installing .NET 4 etc for a simple test asp.net app that had no database.  However - now I'm trying to connect it to the database and am stuck.  Please help.

    I have installed SQL Server Express 2008 on the XP Pro SP3 machine (which I am using as the server) and SQL Server 2008 Express Management Studio to manage it.

    I have copied the database to this production environment and tables etc are all there if i look in SSMSE.  I am using windows authentication and have checked that the login I am using is listed in SSMSE under server/security/logins and a user in database/security/users that references it in Object explorer.

    My connection string in web.config is: connectionString="Server=(local)\SQLExpress;Database=testDB;Integrated Security=true"

    I have tried many other options on this but none work (although maybe just not tried the right one!).

    Please can someone help! - I am getting the following error and stack trace:

     

    Server Error in '/TLDNET' Application.


    Cannot open database "testDB" requested by the login. The login failed.
    Login failed for user 'PHILD\ASPNET'.

    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: Cannot open database "testDB" requested by the login. The login failed.
    Login failed for user 'PHILD\ASPNET'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [SqlException (0x80131904): Cannot open database "testDB" requested by the login. The login failed.
    Login failed for user 'PHILD\ASPNET'.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +183
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
       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) +33
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
       System.Data.SqlClient.SqlConnection.Open() +125
       System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
       System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
       System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1618
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
       System.Web.UI.WebControls.GridView.DataBind() +4
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
       System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
       System.Web.UI.Control.EnsureChildControls() +102
       System.Web.UI.Control.PreRenderRecursiveInternal() +42
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Control.PreRenderRecursiveInternal() +175
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496
    
    Wednesday, August 22, 2012 10:25 AM

Answers

  • User1191505944 posted

    @mackenziedallas

    It's clear that the application is using the asp.net account to access your sql DB, 'PHILD\ASPNET'

    If you add this account to the sql server security logins, your application should work.

    What authentication are you using Windows or forms?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 11:13 AM
  • User357320440 posted

    @mackenziedallas

    It's clear that the application is using the asp.net account to access your sql DB, 'PHILD\ASPNET'

    If you add this account to the sql server security logins, your application should work.

    What authentication are you using Windows or forms?

    Ok i got it working!

    I added the name exactly as above "PHILD\ASPNET" as a Login in Server/Security/Logins and gave it sysadmin role permission.  I then added a user in database/[my db]/security/users with that same exact name as both the login and user name (still don't know which it should have been, so i did both) and now it works.

    Thanks syed.iddi - your answer seems to have helped me most.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 11:59 AM

All replies

  • User2110019919 posted

    Here is a sample connectionstring that has a login/pass within the string:

    <add name="TestDBConn" connectionString="data source=TestPC\SQLEXPRESS;initial catalog=MyTestDB;user id=User1;password=p@ssw0rd;persist security info=True;" providerName="System.Data.SqlClient" />
    
    Check if your security logins match what is within the SQL.
    Wednesday, August 22, 2012 10:45 AM
  • User357320440 posted

    Hi mebinici

    Thanks for your response.  I tried that connectionstring with my own details and still no joy. ("Login failed for user...")

    Forgive me if its a stupid question but how can I tell for sure what the User ID and password should be?  I'm using Windows Authentication.

    I'm not sure what you mean by "Check if your security logins match what is within the SQL."

    Thanks.

    Wednesday, August 22, 2012 10:59 AM
  • User2110019919 posted

    Hi mebinici

    Thanks for your response.  I tried that connectionstring with my own details and still no joy. ("Login failed for user...")

    Forgive me if its a stupid question but how can I tell for sure what the User ID and password should be?  I'm using Windows Authentication.

    I'm not sure what you mean by "Check if your security logins match what is within the SQL."

    Thanks.

    Try this. http://support.webecs.com/KB/a374/how-do-i-configure-sql-server-express-to-enable-mixed.aspx

     

    Wednesday, August 22, 2012 11:10 AM
  • User357320440 posted

    Did that and nothing changed.

    Anyone know how to check for sure I'm using the correct User ID and Password?

    Wednesday, August 22, 2012 11:25 AM
  • User2110019919 posted

    In SQL Server Manager Studio

    Expand the Database --> Expand the Security --> Expand Users.

    You will see a list of user accounts typed with the database. This will indicate if a user was setup, otherwise, read this thread because the user had the same issue with the Windows Authenication.

    http://social.msdn.microsoft.com/Forums/en/Vsexpressinstall/thread/aaf2f68c-4a40-44c8-b7ee-b2f5d94e23c3

     

    Wednesday, August 22, 2012 12:40 PM
  • User1191505944 posted

    Remove

    persist security info=True

    and make sure that the user id has a login in sql server DB

    Wednesday, August 22, 2012 12:45 PM
  • User357320440 posted

    In SQL Server Manager Studio

    Expand the Database --> Expand the Security --> Expand Users.

    You will see a list of user accounts typed with the database. This will indicate if a user was setup,

    Done that.  But I'm still not sure what my User ID should be in the connection string.  In Database/Security/Users I have a User Name: "dbo" who, on clicking properties, has Login Name "PHILD\pad".  Which do I use in the connectionstring (and how can I check the password)?

    otherwise, read this thread because the user had the same issue with the Windows Authenication.

    http://social.msdn.microsoft.com/Forums/en/Vsexpressinstall/thread/aaf2f68c-4a40-44c8-b7ee-b2f5d94e23c3

    Tried that and got stuck on running the script in SSMSE, as did lots of others did more recently at the end of the thread that were never answered (maybe the suggested script needs updating for SQL 2008?).  The error was this:

    Incorrect syntax near 'sp_addLogin'.

    Any clues on that?

    Thanks for your presistent help.  It is much appreciated.

    Thursday, August 23, 2012 4:35 AM
  • User357320440 posted

    Remove

    persist security info=True

    Tried both with and without.  No joy.

    and make sure that the user id has a login in sql server DB

    See my question in previous post.

    Many thanks.

    Thursday, August 23, 2012 4:36 AM
  • User1191505944 posted

    @mackenziedallas

    It's clear that the application is using the asp.net account to access your sql DB, 'PHILD\ASPNET'

    If you add this account to the sql server security logins, your application should work.

    What authentication are you using Windows or forms?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 11:13 AM
  • User357320440 posted

    @mackenziedallas

    It's clear that the application is using the asp.net account to access your sql DB, 'PHILD\ASPNET'

    If you add this account to the sql server security logins, your application should work.

    What authentication are you using Windows or forms?

    I was originally using Windows Authentication but having followed some of the advice above I'm not sure where it stands now!

    In particular I did this:


    STEP1:
    You need to enable SQL Authentication on the machine. This is complex in SQLExpress and you need to edit the registry. Copy the following lines of text onto a Notepad and save it with extention .REG.
    -------------COPY BELOW---------------------------------
    Windows Registry Editor Version 5.00

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer]
    "LoginMode"=dword:00000002
    -------------COPY TILL THIS---------------------------------
    STEP2: Double Click on the .REG file to change the registry. This change the Authentication Mode to enable SQL Authentication.

     

    ... following some advice here http://social.msdn.microsoft.com/Forums/en-GB/Vsexpressinstall/thread/aaf2f68c-4a40-44c8-b7ee-b2f5d94e23c3 that was linked to above (it didn't help because I got stuck after that stage).  After that registry key change does that mean I've now disabled Windows Authentication?

    I would love to ensure that PHILD\ASPNET is added to the sql server logins.  Do I add it with that exact login name (ie - "PHILD\ASPNET")?  What server roles does it need?  Do I aslo need a User in Database/Security/Users with that exact name?

    Thanks.

    Thursday, August 23, 2012 11:47 AM
  • User357320440 posted

    @mackenziedallas

    It's clear that the application is using the asp.net account to access your sql DB, 'PHILD\ASPNET'

    If you add this account to the sql server security logins, your application should work.

    What authentication are you using Windows or forms?

    Ok i got it working!

    I added the name exactly as above "PHILD\ASPNET" as a Login in Server/Security/Logins and gave it sysadmin role permission.  I then added a user in database/[my db]/security/users with that same exact name as both the login and user name (still don't know which it should have been, so i did both) and now it works.

    Thanks syed.iddi - your answer seems to have helped me most.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 23, 2012 11:59 AM
  • User1191505944 posted

    @mackenziedallas

    Please let me know what type of authentication you use? We can configure it accordingly

    Edit: Sorry you answered this

    Thursday, August 23, 2012 12:19 PM