Http://www.cnblogs.com/huangtailang/p/4221164.html
Background: PC is using VS2012, database for 2008r2, recently need to open a SqlServer2012 database if installing a 2012 database on this machine can be a waste of time, Originally want to be in such as WAN network and other service providers to buy a 2012 of the database to use, but found that the current service provider to provide the highest database for 2008r2 since do not want to install a new database version that can only in the present environment to find a way, Fortunately, a local database engine was provided in VS2012. Then try to attach the existing database through the LOCALDB to finally solve: in use Sqlserver2012 Express LocalDB need to install sqllocaldb before (about only a few minutes) principle: Because the database cannot be attached directly in VS database management, it is achieved by creating a database in VS and replacing your database with the database created in vs. VS2012 provides a local database engine sql Server-Express LocalDB, which can be easily managed and used by VS2012, but LocalDB instance names are used when connecting to a previous instance ( LOCALDB) \ Instance Name (LOCALDB) \v11.0[v11.0 is the default instance name of LocalDB] connection string reference: http://www.connectionstrings.com/sqlconnection/ 1. Add a new database by Vs2012 in the V11.0 instance as: Test,test The default address of the database is "C:\Users\ your user name \appdata\local\microsoft\microsoft SQL Server Local db\instances\v11.0 " 2. Close the vs2012 program and end the SQL Server service and the database that will be used (DB2012) The. mdf and. ldf files are copied to the test database folder above If the VS or SQL Server service is not turned off, the following error 3 may not occur when you change the database file. Delete or rename the test database (. MDF and. ldf) 4. Rename your database DB2012 to test (. mdf and. ldf) to implement the replacement 5 of the database. Re-open VS2012 will connect to the v11.0 instance to see the TeThe information in the St database is the information of the previous DB2012. reference: SQL Server Express LocalDB LocalDB connection string My usage instructions: Download a Ninesky article from the Internet, his database is 2012localDB, the connection string is as follows:
<connectionStrings>
<add name= "defaultconnection" connectionstring= "Data source= (LocalDb) \v11.0; attachdbfilename=| Datadirectory|\ninesky.mdf;initial catalog=ninesky;integrated security=true; Multipleactiveresultsets=true "providername=" System.Data.SqlClient "/>
</connectionStrings>
The SQL Server version on my computer is 2008r2, so I can't attach it, but I installed the vs2015,vs2012 to start with LocalDB this local database, 2015 miles must have, how to use that? Open the project first, there is a Server Explorer on the right, for the VS integrated database, right-click on this data connection to modify the connection, pop up 3 shows the modification of the Connection window, the advanced, pop-up 4 shows the advanced properties, in the DataSource bar, the current database source is displayed, select (LocalDb) \ MSSQLLOCALDB Click OK to return to Figure 3 Click on the Test Connection button, test succeeded, 5 shown.
Open the Sqlserver2012 database in Vs2012 using SQL Server Express localdb