在服务器上运行的应用程序 - 无法连接到另一个本地数据库

时间:2014-03-13 19:23:36

标签: asp.net sql asp.net-mvc entity-framework asp.net-mvc-4

我将我的MVC4网站放在运行IIS7.5(.NET4.0)的DEV服务器上,它可以正常指向服务器数据库或指定为[Machine Name] [Sql Instance]的我自己的本地数据库。应用程序在服务帐户下运行的应用程序池中。我确保用户已将该服务帐户添加到其SQL登录名并获得dbo权限。

当我更改连接字符串以使用其他用户的机器,并指定[机器名] [sql实例]时,它会抛出错误。

错误说:

[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: 25 - Connection string is
not valid)]

[EntityException: The underlying provider failed on Open.]

[HttpException (0x80004005): Error executing child request for handler
'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.]

这是连接字符串:

   <add name="ProjectUI" connectionString="metadata=res://*/ViewModels.
   ProjectUI.csdl|res://*/ViewModels. ProjectUI.ssdl|res://*/ViewModels.  
   ProjectUI.msl;provider=System.Data.SqlClient;provider connection string=&quot;data 
   source=MYMACHINEID\MSSQLSERVER;initial catalog=DBName;integrated 
   security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
   providerName="System.Data.EntityClient" />

我尝试的事情:

  • 我在SQL
  • 上验证了远程连接已启用
  • 启用TCP / IP端口
  • 在防火墙中添加了SQL服务器入站规则的例外
  • 使用dbo权限将服务帐户添加到本地数据库

1 个答案:

答案 0 :(得分:0)

有效的设置组合:

  • 启用TCP / IP(和命名管道)
  • 重新启动SQL Server服务
  • 确保服务帐户已添加到数据库并具有适当的权限
  • 无需更改防火墙设置(不允许更改规则)
  • 连接字符串已修改为:数据源= UserMachineID 没有服务器实例(因为它是默认的MSSQLSERVER)