2010-05-02 82 views
1

即使我將Tools-> Options-> Database Tools-> Data Connections設置爲「SIDEKICK」,我在32位XP Professional服務器上從VS獲得以下錯誤「,這是我電腦的名字。換句話說,SIDEKICK應該默認爲完整的SQLSERVER。無法連接來自Visual Studio 2008 9.0的SQL Server實例

換句話說,我希望VS使用SQLSERVER而不是SQLSERVER EXPRESS。我可以清楚地看到服務器資源管理器中的VS以及SSMS 2008中的數據庫。此外,我可以從服務器資源管理器中查看此數據庫的表。我沒有得到任何生成錯誤。它看起來像我的web.config文件中的所有命名是一致的。

我正在開發我的網站根據微軟的教程,所以我不應該得到一個錯誤。然而,我得到下面的異常,當我運行下面這段代碼:

CreateAccounts.aspx.cs文件

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); 

這裏是例外的樣子:

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: 

的Web.config連接字符串看起來像:

<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> 

而且我也關閉防火牆,所以我知道th是不是原因。

+0

你的連接字符串是什麼樣的?你可以使用asterix字符掩蓋密碼和IP地址等,但是請張貼完整的字符串。 – 2010-05-02 21:53:13

+0

謝謝Lasse,我剛剛在上面添加了連接字符串。 – salvationishere 2010-05-02 22:06:15

回答

1

您在「SQL Server配置管理器」中的「SQL Server網絡配置」中啓用了哪些協議?

+0

共享內存和TCP/IP。我需要TCP/IP嗎? – salvationishere 2010-05-02 23:09:03

+0

如果你在同一個盒子上,你不需要tcp/ip – 2010-05-02 23:10:13

+0

現在我發現了這個問題。問題是我試圖使用完整的SQL Server,而不是Express。完整的SQL Server不支持AttachDBFilename選項,它也不支持User Instance = true。 但是,你知道是否選擇TCP/IP的原因當我嘗試從VS打開ASPNET_Users表,通過右鍵單擊並選擇Show Table DAta,我得到的錯誤: 無法打開數據庫...請求的登錄。 – salvationishere 2010-05-02 23:12:28

0

如果您正在使用ASP.NET工作,那麼我會建議你嘗試喜歡用「aspnet_regsql.exe的」實用......基本上可以讓我們改變默認的數據庫連接(這是SQL Express的)東西到我們想要的任何數據庫。此實用程序可以在「C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.more- digits」目錄中找到。

我希望這有助於。

傑克

相關問題