C# 无法从Visual Studio 2008 9.0版连接SQL Server实例
尽管我将工具->选项->数据库工具->数据连接设置为“SIDEKICK”,这是我的计算机名称,但我还是从32位XP Professional服务器上的VS中得到以下错误。换句话说,SIDEKICK应该默认为完整的SQLSERVER 换句话说,我希望VS使用SQLSERVER而不是SQLServerExpress。我可以在ServerExplorer和SSMS2008中从VS清楚地看到我的数据库。此外,我可以在服务器资源管理器中从VS查看此数据库的表。我没有得到任何构建错误。在我的web.config文件中,所有的命名看起来都是一致的 我是根据微软的教程开发我的网站的,所以我不应该得到一个错误。但是,当我运行下面的代码时,我会遇到以下异常: CreateAccounts.aspx.cs文件C# 无法从Visual Studio 2008 9.0版连接SQL Server实例,c#,visual-studio-2008,sql-server-2008,exception,C#,Visual Studio 2008,Sql Server 2008,Exception,尽管我将工具->选项->数据库工具->数据连接设置为“SIDEKICK”,这是我的计算机名称,但我还是从32位XP Professional服务器上的VS中得到以下错误。换句话说,SIDEKICK应该默认为完整的SQLSERVER 换句话说,我希望VS使用SQLSERVER而不是SQLServerExpress。我可以在ServerExplorer和SSMS2008中从VS清楚地看到我的数据库。此外,我可以在服务器资源管理器中从VS查看此数据库的表。我没有得到任何构建错误。在我的web.conf
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:
<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>
web.config连接字符串如下所示:
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:
<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>
我还关闭了防火墙,所以我知道这不是原因。您在“SQL Server配置管理器”中的“SQL Server网络配置”中启用了哪些协议?您在“SQL Server配置管理器”中的“SQL Server网络配置”中启用了哪些协议?如果您正在使用ASP.NET,那么我建议您尝试使用“aspnet\u regsql.exe”实用程序。。。这本质上允许我们将默认数据库连接(即SQL Express)更改为所需的任何数据库。此实用程序可在“C:\WINDOWS\Microsoft.NET\Framework\v2.0.更多数字”目录中找到 我希望这有帮助
Jack如果您正在使用ASP.NET,那么我会建议您尝试使用“aspnet\u regsql.exe”实用程序。。。这本质上允许我们将默认数据库连接(即SQL Express)更改为所需的任何数据库。此实用程序可在“C:\WINDOWS\Microsoft.NET\Framework\v2.0.更多数字”目录中找到 我希望这有帮助
杰克你的连接字符串是什么样子的?您可以用asterix字符屏蔽密码和ip地址等,但请发布完整的字符串。谢谢Lasse,我刚刚在上面添加了连接字符串。您的连接字符串是什么样子的?您可以用asterix字符屏蔽密码和ip地址等,但请发布完整的字符串。谢谢Lasse,我刚刚在上面添加了连接字符串。共享内存和TCP/ip。我需要TCP/IP吗?如果您在同一个框中,您不需要TCP/IP。现在发现问题了。问题是我试图使用完整的SQL Server,而不是Express。完整的SQL Server不支持AttachDBFilename选项,也不支持User Instance=true。但您知道选择TCP/IP是否不好吗?因为当我尝试从VS打开ASPNET_Users表时,通过右键单击并选择Show table DAta,我会得到错误:无法打开数据库。。。由登录名请求。启动消除过程。创建新的asp.net网站。添加gridview和sql数据源,并在此表中查询一些数据。看看它是否有效。“而且完整的SQL Server不支持AttachDBFilename选项”。。你在哪里看到的?共享内存和TCP/IP。我需要TCP/IP吗?如果您在同一个框中,您不需要TCP/IP。现在发现问题了。问题是我试图使用完整的SQL Server,而不是Express。完整的SQL Server不支持AttachDBFilename选项,也不支持User Instance=true。但您知道选择TCP/IP是否不好吗?因为当我尝试从VS打开ASPNET_Users表时,通过右键单击并选择Show table DAta,我会得到错误:无法打开数据库。。。由登录名请求。启动消除过程。创建新的asp.net网站。添加gridview和sql数据源,并在此表中查询一些数据。看看它是否有效。“而且完整的SQL Server不支持AttachDBFilename选项”。。你在哪里看到的?