[error] Cannot open user default database. Login failed.

  • I'm getting the following error, when ASP.NET is trying to create an application database:

    Cannot open user default database. Login failed.

    Explanation:

    The connection string specifies a local Sql Server Express instance using a database location within the applications App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

    1. If the applications App_Data directory does not already exist, the web server account must have read and write access to the applications directory. This is necessary because the web server account will automatically create the App_Data directory if it does not already exist.

    2. If the applications App_Data directory already exists, the web server account only requires read and write access to the applications App_Data directory. This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the applications App_Data directory. Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. This will cause an error when the provider attempts to create a duplicate of an already existing database. Write access is required because the web server accounts credentials are used when creating the new database.

    3. Sql Server Express must be installed on the machine.

    4. The process identity for the web server account must have a local user profile. See the readme document for details on how to create a local user profile for both machine and domain accounts.

    Environment

    SQL Server 2005 Express Edition

    Visual Studio 2008 SP1 + .NET 3.5 SP1

    WinXP SP3

    :w00t:

  • All you need to correct you error is in the thread below if you cannot use what is in that thread you may need a teacher. Please make sure you install IIS 5 before you make the relevant changes, if you are in XP home you need a new operating systems.

    http://social.msdn.microsoft.com/forums/en-US/sqlexpress/thread/7f5f84be-fa09-4cb5-b728-1b0cd30c7d4f/

    Kind regards,
    Gift Peddie

  • Well, I've run the ASP.NET Server Setup Wizard (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe), however I'm getting the following error. I can view tables from MS SQL Server Management Studio Express.

    System.Web.HttpException: Unable to connect to SQL Server database. ---> 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

    at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)

    at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)

    at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)

    at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)

    at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)

    at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)

    at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)

    at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)

    at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)

    at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)

    at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)

    at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)

    at System.Data.SqlClient.SqlConnection.Open()

    at System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString)

    --- End of inner exception stack trace ---

    at System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString)

    at System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install)

    at System.Web.Management.SqlServices.Install(String database, SqlFeatures features, String connectionString)

    at System.Web.Management.ConfirmPanel.Execute()

    Related links:

    http://www.asp.net/learn/videos/video-148.aspx

    http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

    http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

  • You need to delete everything including IIS and again if you don't have IIS running you need to install and configure it, and manually follow the steps.

    Go into SAC and enable both TCP/IP and Named Pipes and allow both local and remote andturn on the browser service, check below for details then manually follow the steps.

    http://support.microsoft.com/kb/914277

    Kind regards,
    Gift Peddie

  • Well, I can try re-installing, however, I got the same error message when I ran the ASP.NET installation wizard on another machine with a similar setup however running Win 2008 Server.

    The following were enabled within SQL Server Configuration Manager:

    SQL Server 2005 Network Configuration > Protocols for SQLEXPRESS

    Shared Memory

    Named Pipes

    TCP/IP

    VIA is disabled

    SQL Native Client Configuration > Client Protocols

    Shared Memory

    TCP/IP

    Named Pipes

  • You need to leave the Admin tool and try to create a connection at the top of VS2008 configure to connection and test the connection if your connection is not correct it will fail. In 2005 you also need to enable both local and remote connection in SAC. If you have not applied it install SQL Server 2005 SP3.

    http://www.microsoft.com/downloads/details.aspx?FamilyID=3181842a-4090-4431-acdd-9a1c832e65a6&displaylang=en

    Kind regards,
    Gift Peddie

  • Thanks for your reply, however, I did not quite understand what to do other than downloading SP3, which I wasn't aware of 🙂

    1. Already checked through the SAC and under JOEY > Database Engine > Remote Connections. Under Local and Remote Connections this is set to Local and Remote Connections. SQL Browser Service is running as well. (see my previous notes)

    In fact now I try to connect from another pc to that SQL server and I'm getting an error message: Login failed for user ". The user is not associated with a trusted SQL Server connection (Microsoft SQL Server Error 18452). I've changed the server authentication from Windows Authentication Mode to SQL Server and Windows Authentication Mode, however I still have to troubelshoot this issue, presumably create some trusted connection...

  • If you did not install SQL Server 2005 with SP3 then you need to install it, a side note you may need a teacher because this configuration is wizard based so it will run as expected. When yours is not running you are not doing it right. Run the code below to see if you have SP3 installed, if not install it.

    SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

    Kind regards,
    Gift Peddie

  • Well I ran the wizard downloaded at

    http://www.microsoft.com/downloads/thankyou.aspx?familyId=b448b0d0-ee79-48f6-b50a-7c4f028c2e3d&displayLang=en, and, it seems I the latest SP is already installed, since my only option is to 'upgrade'.

    When I run the query however, the 2nd field reads: sp2...

    :w00t:

  • The one you ran is Express with Advanced Server and SP3 you need to use 32 version in the link I provided.

    Kind regards,
    Gift Peddie

  • I thought it was a mistake, because I have the Advanced Edition.

    "You must use SQL Server Express with Advanced Services SP3 to upgrade instances of SQL Server Express with Advanced Services to SP3."

    Taken from the release notes.

  • "You must use SQL Server Express with Advanced Services SP3 to upgrade instances of SQL Server Express with Advanced Services to SP3."

    Release notes at (http://download.microsoft.com/download/F/4/E/F4E80C76-3B69-4A42-A90B-79AEACA1177D/SQLExpress2005SP3RelNotes.htm#download)

  • If that is the requirement for the Express Advanced Services then upgrade to SP3 and watch more membership related videos before trying to write code.

    Kind regards,
    Gift Peddie

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply