2015-02-24 69 views
0

我這是在一個窗口服務託管WCF服務,而當它連接到它產生以下錯誤的LocalDB數據庫:無法連接到的LocalDB作爲系統

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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist

這是我的連接字符串:

<add name="CredentialEntities" 
    connectionString="metadata=res://*/Credential.csdl|res://*/Credential.ssdl|res://*/Credential.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=(localdb)\projects;Initial Catalog=Credentials;Integrated Security=True&quot;" 
    providerName="System.Data.EntityClient" /> 

我可以通過SQL Server Management Studio連接到這個數據庫沒有問題,我也可以通過Visual Studio將數據連接連接到數據源。 當我作爲我的帳戶運行Windows服務時,它可以成功運行。

我曾嘗試加入NT AUTHORITY\SYSTEM帳戶作爲SQL Server中的系統管理員,但沒有運氣

+0

在這裏查看關於連接字符串以及如何格式化[C#connectionsStrings](http://www.connectionstrings.com)'fyi'使用'SqlDataClient'連接到sql server並通過' EF'的連接字符串是不一樣的 – MethodMan 2015-02-24 14:59:31

+0

我的連接字符串可以正常使用我的帳戶,但不是本地系統帳戶 – jazza1000 2015-02-24 15:04:06

回答

0

建議你考慮添加專用的數據庫訪問(例如myServiceUser)的用戶,然後設置新用戶作爲Windows服務帳戶。最後,添加必要的SQL服務器權限以允許專用SQL Server訪問用戶帳戶查詢目標視圖並調用相關過程。

+0

嗯,我可以這樣做,但只是想知道爲什麼它不能像本地系統用戶那樣工作。 SQLExpress沒有任何問題。我也可以作爲一個SQL帳戶運行,但這些是變通辦法 – jazza1000 2015-02-24 15:00:37

+0

下面的文章似乎提供了一個全面的選項概述:http://stackoverflow.com/questions/26597498/using-sql-localdb-in-a-windows-服務 – Seymour 2015-02-24 15:21:29

相關問題