最近在忙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

总结:
在百度上找很少相似的问题的解答,仍是得靠谷歌字符串