sql-server - 无法从 MVC 应用程序连接到 SQL Server Express 2008

标签 sql-server asp.net-mvc-3 sql-server-express

我全新的 Server 2008 R2 服务器将不接受来 self 的 MVC3 应用程序的连接。

我已经尝试让这个工作 3 天了。它只是不会通过浏览器连接。但是,我可以使用用户凭据通过 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):

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)]

如何解决这个问题?

最佳答案

我会检查的一些故障排除事项:

  • 您的代码是否明确使用了 Main.ConnectionString?仔细检查——我见过 LINQ To SQL 在 .dbml 中有硬编码连接字符串的实例。我知道您没有提到 LINQ To SQL,但这也适用于 EF。

  • 在您的代码中搜索任何残留的硬编码连接字符串。

  • 使用新构建重新部署您的项目

  • 您的开发工作站使用相同的连接字符串是否连接正常?

关于sql-server - 无法从 MVC 应用程序连接到 SQL Server Express 2008,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5439274/

相关文章:

asp.net-mvc-3 - 在MVC3中的WebGrid列中应用特定的宽度

mysql - SQL Server Management Studio 查看和更改表

sql-server - SQL Server Analysis Services - 我有吗?

sql - 使具有多个where条件和变量的SQL查询更加高效

asp.net-mvc-3 - ASP.NET MVC - 如何使用 jquery.validate.unobtrusive lib 防止双击提交?

javascript - 如何创建可与嵌入代码一起使用的按钮?

sql - JSL 连接到 SQL Server Express 设置 DSN

mysql - Linq 与 MySql

sql - 即使成功更新后,T-SQL 过程、标量变量也会出错

c# - 无法使用 smo 从 C# 执行脚本