无法连接到 SQL Server 数据库

发布于 2024-08-19 17:13:23 字数 5216 浏览 5 评论 0原文

我无法连接到 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”,旁边有一个测试链接。我单击“测试”并收到以下错误消息:

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

此页面上唯一的其他选项是单击“后退”。

有人可以帮我解决这个问题吗?已经过去一周多了,我到处搜索答案,并得到了很多没有帮助的帖子链接。我将不胜感激任何帮助。

我尝试运行配置表面工具并启用管道、本地/远程连接,尽管这没有任何区别。

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

到目前为止还没有运气。

请帮忙 谢谢

Bael

编辑

此后我尝试禁用防火墙更改端口,但没有成功。

解决方案

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

我设法通过卸载 SQL Server 2005 和 2008 来修复所有错误。然后注册、下载 SQL Server Express Edition 2008(带有管理工具)并安装它们。

安装完成后,我关闭了 Visual Web Developer,再次打开它,然后在打开 ASP.NET 网站管理工具后单击“安全”选项卡,一切都“正常工作”了……

I cannot connect to SQL Server Database.

I am trying to setup Membership with roles on my website using the MSDN Tutorial. It used to work only locally on my machine, however after following advice given on different forums, and on stackoverflow, the situation worsened, and now I can't even connect to the SQL Server Database.

When I run the aspnet.regsql.exe utility, I get the following error message:

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

Also, I am unable to use the ASP.NET Website Adimistration Tool. When I click on the Security tab I receive the following error:

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

So, I click on the 'Choose Data Store' button as instructed, which allows me to select a a Provider. The provider is named 'AspNetSqlProvider', it has a Test link beside it. I click on Test and receive the following error message:

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

The only other option on this page is to click "Back".

Can somebody please help me sort this out? It's been over a week now and I've searched high and low for answers and have been given so many links to posts that have been of no help. I'd appreciate any help at all.

I have tried running the Configuration Surface Tool and enabling pipes, local/remote connections, though this has made no difference at all.

I have even gone so far as to completely uninstall Visual Web Developer and SQL Server 2005 and 2008 and delete all traces left behind of these applications, and then re-downloaded them all and re-installed them all again.

No luck so far.

Please help
Thanks

Bael

Edit:

I have since tried disabling my firewall changing the port, with no luck.

SOLUTION:

Yes, this may be a little drastic. And I think that this solution should only be a last resort when all else fails.

I managed to fix whatever was wrong by uninstalling SQL Server 2005 and 2008. And then Registering for, downloading SQL Server Express Edition 2008 (with Management Tools) and installing them.

After installation was complete, I closed Visual Web Developer, opened it again, and clicked on the Security tab after opening ASP.NET Website Administration Tool and everything has just "worked" since...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春庭雪 2024-08-26 17:13:23

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

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

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

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

Can you connect using sqlcmd locally?
Can you connect using sqlcmd from a remote machine?

Are you using a SQL username/password, or trusted Windows authentication? If the latter, run CommandPrompt/Powershell as a different user and see if you can connect.

My guess is that you haven't added logins to SQL, and that you're running aspnet.regsql.exe without escalated privileges. If it runs successfully from a Command Prompt that was Run As Administrator, then this is a useful sign.

There are a number of potential issues, but the escalated privileges is something I see often these days. It's better to create a dedicated account, give that an appropriate amount of access to the SQL instance, and then run Command Prompt as that account (shift-right-click to get the old 'Run as' option).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文