无法从 MVC 应用程序连接到 SQL Server Express 2008
我的全新 Server 2008 R2 服务器将不接受来自我的 MVC3 应用程序的连接。
我已经尝试让它工作三天了。它只是不会通过浏览器连接。不过,我可以使用用户凭据通过 SQL Server Mgmt Studio 登录,也可以以管理员身份登录。
我已完成以下操作:
- 设置要接受的远程连接(即使 IIS 和 SqlExpress 在同一机器上运行)
- 启用命名管道/tcp/共享内存
- 禁用 TCP 配置的动态端口(我将其设为空白)
- TCP 配置的指定端口
- 禁用 Windows 防火墙
我意识到这是一个一般错误,但它只是无法连接。
连接字符串:
add name="Main.ConnectionString"
connectionString="Data Source=.\sqlexpress;Initial Catalog=BJ;User Id=Jameson;Password=pass!;"
我收到以下错误(YSOD):
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供程序:SQL 网络接口,错误:26 - 定位指定的服务器/实例时出错)
[SqlException (0x80131904):建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 - 定位指定的服务器/实例时出错)]
如何修复此问题?
My brand new Server 2008 R2 Server will not accept connections from my MVC3 application.
I have been trying to get this working for 3 days. It just will not connect via the browser. However I can log on via SQL Server Mgmt Studio with the user credentials, also as administrator.
I have done the following:
- Setup remote connections to be accepted (even though IIS and SqlExpress are running on the same box)
- Enabled named pipes/tcp/shared memory
- Disabled Dynamic Ports for TCP configuration (my making it blank)
- Specified port for TCP configuration
- Disabled windows firewall
I realize this is a generic error but it just won't connect.
Connection string:
add name="Main.ConnectionString"
connectionString="Data Source=.\sqlexpress;Initial Catalog=BJ;User Id=Jameson;Password=pass!;"
I get the following error (YSOD):
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)
[SqlException (0x80131904): 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)]
How can this be fixed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我要检查的一些故障排除事项:
您的代码是否显式使用
Main.ConnectionString
?仔细检查这一点——我见过 LINQ To SQL 在 .dbml 中有硬编码连接字符串的实例。我知道您没有提到 LINQ To SQL,但这也适用于 EF。在代码中搜索硬编码连接字符串的任何剩余部分。
使用新版本重新部署您的项目
您的开发工作站是否可以使用相同的连接字符串正常连接?
A few troublehshooting things I'd check:
is your code explicitly using the
Main.ConnectionString
? Double check this -- I've seen instances where a LINQ To SQL had a hardcoded connection string in the .dbml. I realize you didn't mention LINQ To SQL, but this could go for EF as well.search your code for any remnant of a hard-coded connection string.
redeploy your project with a new build
does your dev workstation connect OK with the same connection string?
如果您使用 SQL 身份验证,您的连接字符串应如下所示:
如果您使用 Windows 身份验证:
还要确保防火墙没有阻止连接。
有关详细信息,请查看以下网站。如果您在配置 SQL Server 时仍然遇到问题,请随时在 https://serverfault.com/ 上提出您的问题
If you are using SQL authentication your connection string should look like this:
and if you are using Windows Authentication:
Also make sure a firewall is not blocking connections.
For more info checkout the following site. And if you still have troubles configuring your SQL Server don't hesitate to ask your question on https://serverfault.com/