Failed to generate a user instance of SQL Server.

  • My SqlExpress application was running fine, I renamed the ASPNETDB database (it was called [C:\inetpub\wwwroot\website1\App_Data\ASPNETDB.mdf] and the application ran ok. I then tried removing the Integrated Security=SSPI and using a username and password in the connection string. This also worked for a while, but I started getting this error:

    Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.

    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.

    [SqlException (0x80131904): Failed to generate a user instance of SQL Server. Only an integrated connection can generate a user instance. The connection will be closed.]

    System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5296071

    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558

    System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682

    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69

    System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +30

    ... Yada Yada ...

    I have reverted to the connection string, but am still getting the error. I've tried User Instance=false - same error. Googling suggested removing the C:\Users\<username>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory - same error. I can still connect to SQLEXPRESS using SSMS - its just the ADO.NET connection that fails.

    Also tried rebooting and restarting SQLEXPRESS.

    List of connection Strings tried: (none work)

    <add name="ConStr_Main" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=false" providerName="System.Data.SqlClient" />

    <add name="ConStr_Main" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />

    <add name="ConStr_Main" connectionString="data source=.\SQLEXPRESS;Uid=UserName;Pwd=Password;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=false" providerName="System.Data.SqlClient" />

    <add name="ConStr_Main" connectionString="data source=.\SQLEXPRESS;Uid=UserName;Pwd=Password;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />

    I am out of ideas.

  • What fixed this was connecting to SqlExpress in Visual Studio, Server Explorer - creating a new data connection.

    This re-created the C:\Users\<username>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory - with default copies of msdb, master and tempdb

Viewing 2 posts - 1 through 1 (of 1 total)

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