Unable to connect SQL Server instance from Visual Studio 2008 Version 9.0

Posted by salvationishere on Stack Overflow See other posts from Stack Overflow or by salvationishere
Published on 2010-05-02T21:48:53Z Indexed on 2010/05/02 22:08 UTC
Read the original article Hit count: 319

I am getting the below error from VS on an 32-bit XP Professional server even though I set Tools->Options->Database Tools->Data Connections to "SIDEKICK", which is the name of my computer. In other words SIDEKICK should default to the full SQLSERVER.

In other words, I want VS to use SQLSERVER instead of SQLSERVER EXPRESS. And I can clearly see my database both from VS in the Server Explorer and also in SSMS 2008. Furthermore, I can view the tables of this database in Server Explorer from VS. I do not get any build errors. And it looks like all of the naming is consistent in my web.config file.

I am developing my website according to a Microsoft tutorial, so I should not be getting an error. Yet I get the following exception when I run this code below:

CreateAccounts.aspx.cs file

protected void CreateAccountButton_Click(object sender, EventArgs e)
    {
        MembershipCreateStatus createStatus;
//This line below is where the exception occurs
        MembershipUser newUser = Membership.CreateUser(Username.Text, Password.Text, Email.Text, passwordQuestion, SecurityAnswer.Text, true, out createStatus);

And here is what the exception looks like:

System.Web.HttpException was unhandled by user code
  Message="Unable to connect to SQL Server database."
  Source="System.Web"
  ErrorCode=-2147467259
  StackTrace:
       at System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString)
       at System.Web.DataAccess.SqlConnectionHelper.EnsureSqlExpressDBFile(String connectionString)
       at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation)
       at System.Web.Security.SqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status)
       at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status)
       at System.Web.Security.Membership.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, MembershipCreateStatus& status)
       at Membership_CreatingUserAccounts.CreateAccountButton_Click(Object sender, EventArgs e) in c:\Documents and Settings\Admin\My Documents\Visual Studio 2008\WebSites\WebSite2\Membership\CreatingUserAccounts.aspx.cs:line 24
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.Web.HttpException
       Message="Unable to connect to SQL Server database."
       Source="System.Web"
       ErrorCode=-2147467259
       StackTrace:
            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, String dbFileName, String connectionString)
            at System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString)
       InnerException: System.Data.SqlClient.SqlException
            Message="The user instance login flag is not supported on this version of SQL Server. The connection will be closed."
            Source=".Net SqlClient Data Provider"
            ErrorCode=-2146232060
            Class=14
            LineNumber=65536
            Number=18493
            Procedure=""
            Server="."
            State=1
            StackTrace:
                 at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
                 at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
                 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, 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.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
                 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)
            InnerException: 

The web.config connection string looks like:

<connectionStrings>
    <add name="SecurityTutorialsConnectionString"      
         connectionString="data source=.;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SecurityTutorialsDatabase3.mdf;User Instance=true"      
         providerName="System.Data.SqlClient"/>

</connectionStrings>
<system.web>
    <membership defaultProvider="SecurityTutorialsSqlMembershipProvider">
        <providers>
            <add name="SecurityTutorialsSqlMembershipProvider"                
                 type="System.Web.Security.SqlMembershipProvider"                
                 connectionStringName="SecurityTutorialsConnectionString"                
                 enablePasswordRetrieval="false"                
                 enablePasswordReset="true"                
                 requiresQuestionAndAnswer="true"                
                 applicationName="SecurityTutorials"                
                 requiresUniqueEmail="true"                
                 passwordFormat="Hashed"                
                 maxInvalidPasswordAttempts="5"                
                 minRequiredPasswordLength="7"                
                 minRequiredNonalphanumericCharacters="1"                
                 passwordAttemptWindow="10"                
                 passwordStrengthRegularExpression=""/>
        </providers>
    </membership>

© Stack Overflow or respective owner

Related posts about c#

Related posts about visual-studio-2008