2011-03-25 124 views
3

我的全新Server 2008 R2 Server不接受来自我的MVC3应用程序的连接。无法从MVC应用程序连接到SQL Server Express 2008

我一直试图让这工作3天。它只是不会通过浏览器连接。但是,我可以通过SQL Server Mgmt Studio以用户凭据登录,也可以以管理员身份登录。

我也做了以下内容:

  • 设置远程连接被接受
  • 启用命名管道/ TCP /共享存储器
  • 禁用(即使IIS和SQLEXPRESS在同一机器上运行)用于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)]

如何这个问题能解决?

+0

什么是您的实例的名称* SQLEXPRESS *?你的连接字符串是什么样的?(当然秘密位已更改) – Tahbaza 2011-03-25 23:54:27

回答

2

几troublehshooting东西的问题,我会检查:

  • 是你的代码明确使用Main.ConnectionString?仔细检查 - 我已经看到LINQ To SQL在.dbml中有一个硬编码连接字符串的情况。我意识到你没有提到LINQ To SQL,但是这也可以用于EF。

  • 在您的代码中查找硬编码连接字符串的任何残余。

  • 重新部署将项目与新的构建

  • 没有你的开发工作站相同的连接字符串连接OK?

+0

我在应用程序中使用了一个硬编码的查询字符串,并且以某种方式调用了该字符串。谢谢你的帮助。 – 2011-03-26 17:56:29

+1

@Dr .:没问题,很高兴帮忙!请记住用绿色选中标记“接受”最佳答案。它是StackOverflow声誉系统的一部分。 – 2011-03-26 19:06:25

2

如果您使用的是SQL身份验证的连接字符串应该是这样的:

Data Source=myServerAddressIP\SQLEXPRESS;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword; 

,如果你正在使用Windows身份验证:

Data Source=myServerAddressIP\SQLEXPRESS;Initial Catalog=myDataBase;Integrated Security=SSPI; 

还要确保防火墙不会阻止连接。

欲了解更多信息结账following site。如果你仍然有麻烦配置您的SQL Server不要犹豫,问你对https://serverfault.com/

相关问题