最近在忙ASP.NET的大作業(yè),使用的是VS2012吹由,筆者圖方便若未,想使用其內(nèi)置的數(shù)據(jù)庫,但是在連接字符串上遇到了不少的麻煩溉知。折騰了很久陨瘩,終于解決腕够,鑒于網(wǎng)上都是基于VS2008的教程级乍,實在太老,所以筆者把解決方案拿出來帚湘,也算是給看客指條路玫荣。
問題描述
在VS2012中,對連接字符串有一些新的更改大诸,下面的英文是我在微軟連接字符串的頁面上截取的捅厂。
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:
- 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的使用進行了規(guī)范:
- 在SQL Server Express databases需要將其移除,LocalDB實例都是“用戶實例”贿堰,并且不需要在連接字符串中指定User Instance = true辙芍。
- 在LocalDB databases中,則需要;User Instance=True 這里要注意羹与,把最后的";"移除故硅。
連接字符串
官網(wǎng)給的列表
總結(jié):
在百度上找不多類似的問題的解答,還是得靠谷歌