SQL Server:无法从本地网站连接(SQL 网络接口,错误:26 - 错误定位服务器/指定的实例) [英] SQL Server: cannot connect from local website (SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

查看:55
本文介绍了SQL Server:无法从本地网站连接(SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Visual Studio 2008 和 Sql Server 2008 Express 开发网站.我进入了开发,所以代码是正确的,因为我的一些同事使用相同的工具正确运行它.问题是:一旦我运行网站我就无法让它与数据库通信.他们都在我的本地机器上.抛出的错误是:

I'm developing a website using Visual Studio 2008 and Sql Server 2008 Express. I entered into developing, so code is right as there are some coleagues of mine running it correctly with the same tools. The problem is: once I run the website I cannot make it comunicate with the database. They both are in my local machine. The error thrown is:

与 SQL Server 建立连接时发生与网络相关或特定于实例的错误.服务器未找到或无法访问.验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接.(提供程序:SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

奇怪的是,我可以通过 Data Explorer 面板通过 Visual Studio 本身导航数据库.通过这样做,我从属性中读取了连接字符串,它看起来像

The strange stuff is that I can navigate the db throught Visual Studio itself, via the Data Explorer panel. By doing that, I read the connection string from properties, and it looks like

Data Source=*MY_MACHINE*\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

Data Source=*MY_MACHINE*\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

我也尝试了一些改变,比如

I also tried some change like

Data Source=.\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

Data Source=.\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

Data Source=localhost\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

Data Source=localhost\SQLEXPRESS;Initial Catalog=*MY_DB*;Integrated Security=True

两者都没有结果.

谢谢

推荐答案

问题是 ASP.NET 工作进程没有访问数据库的权限.

The problem is the ASP.NET worker process does not have rights to access the database.

有多种方法可以解决此问题,但最简单的方法是授予本地组所有人访问数据库的权限.然后你应该可以连接了.

There are a number of ways to fix this, but the simplest is to give local group everyone rights to the database. Then you should be able to connect.

您可以将连接字符串更改为不使用集成安全,而是为其提供用户名和密码

You could change the connection string to not use Integrated Security but give it a username and password

您还应该在事件日志中看到相应的错误消息(说明不允许某某某用户访问数据库),然后您可以仅授予该用户权限.

You should also see an appropriate error message in your event log (saying USER such and such was not allowed to access the database) then you can give rights to just that user.

当您以自己的身份跑步时,您就是在以自己的身份进行连接,并且您拥有权利.当 IIs 运行时,它作为工作进程运行,该用户无法连接.

When you are running as yourself you are connecting as yourself and you have rights. When IIs is running then it is running as the worker process and that user can't connect.

这篇关于SQL Server:无法从本地网站连接(SQL 网络接口,错误:26 - 错误定位服务器/指定的实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆