【发布时间】:2015-04-26 06:13:33
【问题描述】:
我有一个托管在 Windows 服务中的 WCF 服务,当它连接到 localdb 数据库时,它会产生以下错误:
在建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。 (提供者:SQL 网络接口,错误:50 - 发生本地数据库运行时错误。指定的 LocalDB 实例不存在
这是我的连接字符串:
<add name="CredentialEntities"
connectionString="metadata=res://*/Credential.csdl|res://*/Credential.ssdl|res://*/Credential.msl;provider=System.Data.SqlClient;provider connection string="Data Source=(localdb)\projects;Initial Catalog=Credentials;Integrated Security=True""
providerName="System.Data.EntityClient" />
我可以通过 SQL Server Management Studio 连接到这个数据库没有问题,我也可以通过 Visual Studio 数据连接连接到数据源。 当我将 windows 服务作为我的帐户运行时,它可以成功运行。
我尝试在 SQL Server 中将NT AUTHORITY\SYSTEM 帐户添加为系统管理员,但没有成功
【问题讨论】:
-
看看这里关于连接字符串以及如何格式化它们C# connectionsStrings
fyi使用SqlDataClient连接到sql server并通过EF连接到sql server连接字符串不是一样的 -
我的连接字符串可以在我的帐户中正常工作,但不能作为本地系统帐户
标签: c# sql-server wcf localdb