无法连接到SQL Server数据库

时间:2010-01-29 01:53:31

标签: sql sql-server database visual-web-developer

我无法连接到SQL Server数据库。

我正在尝试使用MSDN教程在我的网站上设置角色成员资格。它过去只在我的机器上本地工作,但是在遵循不同论坛和stackoverflow上给出的建议之后,情况变得更糟,现在我甚至无法连接到SQL Server数据库。

当我运行aspnet.regsql.exe实用程序时,收到以下错误消息:

"Setup failed.

Exception:
Unable to connect to SQL Server database.

----------------------------------------
Details of failure
----------------------------------------

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()"

另外,我无法使用ASP.NET网站管理工具。当我单击“安全”选项卡时,收到以下错误:

"There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store. 

The following message may help in diagnosing the problem: Unable to connect to SQL Server database."

因此,我按照指示点击“选择数据存储”按钮,这样我就可以选择一个提供商。提供程序名为“AspNetSqlProvider”,旁边有一个Test链接。我单击测试并收到以下错误消息:

"Could not establish a connection to the database. 
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider."

此页面上唯一的其他选项是点击“返回”。

有人可以帮我解决这个问题吗?现在已经过了一个多星期了,我已经搜索了高低的答案,并且已经给了很多链接,这些帖子都没有帮助。我会感激任何帮助。

我尝试过运行Configuration Surface Tool并启用管道,本地/远程连接,尽管这根本没有任何区别。

我甚至完全卸载了Visual Web Developer和SQL Server 2005和2008并删除了这些应用程序留下的所有痕迹,然后重新下载它们并重新安装它们。

到目前为止没有运气。

请帮忙 感谢

巴尔

修改

我已经尝试过禁用我的防火墙更改端口,没有运气。

是的,这可能有点激烈。而且我认为这个解决方案应该只是其他所有方法都失败的最后手段。

我设法通过卸载SQL Server 2005和2008来解决任何问题。然后注册,下载SQL Server Express Edition 2008(使用管理工具)并安装它们。

安装完成后,我关闭了Visual Web Developer,再次打开它,并在打开ASP.NET网站管理工具后点击了“安全”选项卡,所有内容都刚刚“工作”......

1 个答案:

答案 0 :(得分:1)

您可以在本地使用sqlcmd进行连接吗? 你可以使用来自远程机器的sqlcmd进行连接吗?

您使用的是SQL用户名/密码还是受信任的Windows身份验证?如果是后者,请以不同的用户身份运行CommandPrompt / Powershell,看看是否可以连接。

我的猜测是你没有向SQL添加登录,并且你正在运行没有升级权限的aspnet.regsql.exe。如果它从以管理员身份运行的命令提示符成功运行,那么这是一个有用的标志。

有许多潜在的问题,但升级的权限是我现在经常看到的。最好创建一个专用帐户,为SQL实例提供适当的访问权限,然后以该帐户运行命令提示符(右键单击右键以获取旧的“运行方式”选项)。