2014-09-20 114 views
2

我已經使用Visual Studio 2012的數據庫...... 當我嘗試重新連接,然後在這裏我們運行應用程序的異常enter image description hereVisual Studio中的數據庫連接錯誤?

注意連接丟失:前面的文件被誤刪,並試圖附加新的它說它已經存在? 解決方案是什麼?

+0

您將MSVC 2012 IDE連接到哪個數據庫系統?是MSDN,Sqllite還是Mysql數據庫? – Juniar 2014-09-20 17:57:33

回答

0

在你的連接字符串中只需添加'database ='即可。這可以防止SQL Server創建自動命名的數據庫。

+0

你能解釋一下嗎?這是連接字符串,我必須把它放在? Data Source =(LocalDB)\ v11.0; AttachDbFilename ='C:\ Users \ Talah \ Documents \ Visual Studio 2012 \ ACMS.mdf'; Integrated Security = True; Connect Timeout = 30「); – 2014-09-20 17:10:22

+0

的app.config – 2014-09-21 16:13:53

2

你在運行什麼樣的數據庫?請指定:

如果您有SQLEXPRESS數據庫: 首先,您需要像這樣更改數據源名稱。

"Data Source=(LocalDB)\v11.0" to "Data Source=.\SQLEXPRESS" 

要連接到本地SQL Server實例,發出以下字符串:

Server=.\SQLExpress;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;Database=dbname Trusted_Connection=Yes; 

要與位於數據目錄的數據庫文件,發出以下字符串連接到本地SQL Server實例:

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname Trusted_Connection=Yes; 

要連接到的LocalDB實例自動,發出以下字符串:

Server=(localdb)\v11.0;Integrated Security=true; 

要與特定的數據連接的LocalDB自動實例,發出以下字符串:

Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=C:\MyFolder\MyData.mdf; 

要連接到的LocalDB命名實例,發出以下字符串:

Server=(localdb)\MyInstance;Integrated Security=true; 

您需要獲取一個與您的特定數據庫完全匹配的字符串,以便連接。