最近在忙ASP.NET的大做業,使用的是VS2012,筆者圖方便,想使用其內置的數據庫,可是在鏈接字符串上遇到了很多的麻煩。折騰了好久,終於解決,鑑於網上都是基於VS2008的教程,實在太老,因此筆者把解決方案拿出來,也算是給看客指條路。數據庫
問題描述
在VS2012中,對鏈接字符串有一些新的更改,下面的英文是我在微軟鏈接字符串的頁面上截取的。this
Converting Connection Strings between LocalDB and SQL Server Express
How to Convert a SQL Server Express Connection String to LocalDB Project templates for Visual Studio 2010 and Visual Web Developer 2010 Express create connection strings that specify SQL Server Express databases. To convert one of these connection strings to LocalDB, make the following changes:orm
- Change "Data Source=.\SQLEXPRESS" to "Data Source=(LocalDB\v11.0)". This change assumes that you installed LocalDB with the default instance name. For more information, see Data Source later in this topic.
- Remove "User Instance=True" if it is present. Also remove the preceding or following semicolon (;).
How to Convert a LocalDB Connection String to SQL Server Express
Project templates for Visual Studio 2012 and Visual Studio Express 2012 for Web create connection strings that specify LocalDB databases. To convert one of these connection strings to SQL Server Express, make the following changes:教程
- Change "Data Source=(LocalDB)\v11.0" to "Data Source=.\SQLEXPRESS". This change assumes that you installed SQL Server Express with the default instance name. For more information, see Data Source later in this topic.
- If the connection string contains AttachDBFileName, add at the end ";User Instance=True". Omit the semicolon (;) if the connection string already ends with one.
能夠看出其中VS2012相對於VS2010的變化:圖片
- 若是是鏈接SQL Server Express databases,須要將鏈接字符串定義爲:Data Source=.\SQLEXPRESS" to "Data Source=(LocalDB\v11.0)
- 若是是鏈接LocalDB databases,須要將鏈接字符串定義爲:Data Source=(LocalDB)\v11.0" to "Data Source=.\SQLEXPRESS
Data Source的值有本身的定義,同時對User Instance的使用進行了規範:ci
- 在SQL Server Express databases須要將其移除,LocalDB實例都是「用戶實例」,而且不須要在鏈接字符串中指定User Instance = true。
- 在LocalDB databases中,則須要;User Instance=True 這裏要注意,把最後的";"移除。
鏈接字符串
官網給的列表rem
![在這裏輸入圖片標題 列表部分圖片](http://static.javashuo.com/static/loading.gif)
總結:
在百度上找很少相似的問題的解答,仍是得靠谷歌字符串