繁体   English   中英

无法连接到SQL Server数据库

[英]Cannot connect to SQL Server Database

我无法连接到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工具并启用管道,本地/远程连接,尽管这一点都没有影响。

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

到目前为止没有运气。

请帮忙谢谢

巴尔

编辑

此后,我一直尝试禁用防火墙来更改端口,但是没有运气。

解决方案

是的,这可能有点夸张。 我认为,只有在所有其他方法都失败时,该解决方案才应该是万不得已的方法。

通过卸载SQL Server 2005和2008,我设法解决了所有错误。然后进行注册,下载SQL Server Express Edition 2008(使用管理工具)并安装它们。

安装完成后,我关闭了Visual Web Developer,再次将其打开,然后在打开ASP.NET网站管理工具后单击“安全性”选项卡,自此以来,一切都“正常”进行了...

您可以在本地使用sqlcmd进行连接吗? 您可以使用sqlcmd从远程计算机进行连接吗?

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

我的猜测是您尚未向SQL添加登录名,并且您正在运行没有升级特权的aspnet.regsql.exe。 如果它通过以管理员身份运行的命令提示符成功运行,则这是一个有用的标志。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM