2015-01-11 32 views
0

我剛剛安裝了Visual Studio 2012 Express版for web,我試圖連接到Mvc 4項目中的localdb。連接字符串應該如何寫入MVC 4

在SQL Server Management Studio中,我能夠成功連接是這樣的:

enter image description here

而且我的連接字符串(應用程序)是這樣的:

connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=test;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\test.mdf"

然而,我得到一個錯誤,告訴「在建立到SQL Server的連接時發生了與網絡相關或特定於實例的錯誤。服務器未找到或無法訪問。 「

任何想法在這裏有什麼錯?

+0

剛剛'Server =(localdb)\ v11.0; Database = test; Integrated Security = SSPI;'? – Ofiris

+0

這應該做到這一點:connectionString =「數據源=(LocalDB)\ v11.0; AttachDbFilename = | DataDirectory | \ test.mdf;集成安全= SSPI」 –

+0

@Ofiris我試了兩個。沒有工作:(但我可以連接'SQL服務器管理工​​作室' –

回答

0

True嘗試使用Integrated Security作爲this article explaind,樣品:

Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\test.mdf;Integrated Security=True

確保SQL Server服務的計算機上運行。

另一方面,您可以檢查www.connectionstrings.com。這是一個很好的網站,爲每個差異場景找到正確的連接字符串。

+0

謝謝。很抱歉,因爲天真,但我去了'services.msc',並沒有什麼叫'sql server'。任何錯誤的東西? –

+0

但是'sql server management studio'能夠連接數據庫,但是從應用程序我無法連接 –

+1

您正在連接本地DB文件(test.mdf),因此不需要sql server。 –