Detailed example of VS2015 with LOCALDB database usage

Source: Internet
Author: User
This article is mainly for everyone in detail introduced the use of VS2015 LocalDB database, with a certain reference value, interested in small partners can refer to

For programmers, the programming process is more or less dealing with the database. If you are using Visual Studio for program development, Microsoft's SQL Server database is the best choice. But the problem is that the SQL Server database is prone to a few grams, and the amount of space that is used after installation is quite large, is it not every developer who needs to install SQL Server at the time of development? In fact, for small projects, test-oriented projects, learning project development, there is no need to use SQL Server so large database. Microsoft is well aware of this, so it has introduced a super-simplified version of the SQL Server database: SQL Server LocalDB. This small database can fully meet the development and debugging of ordinary projects, the key is that it only dozens of m, can greatly reduce the operating pressure of the PC. This article provides a brief introduction to how the LOCALDB database is used in Visual Studio 2015.

First, the installation of LocalDB

The LOCALDB is installed automatically when the VS2015 is installed, so localdb is certain if the VS2015 is properly installed.

Ii. connection and management of LOCALDB

Enter VS2015, and in the view Select Sql Server Object Explorer, you can see the following interface.

You can select Add SQL Server by right-clicking SQL Server.

Browse locally in the pop-up form, and you can see two DB instances: Mssqllocaldb and ProjectsV13. These two instances are VS2015 with localdb, the reason is two, because the landlord's VS2015 has been updated, Mssqllocaldb is V12 version localdb,projectsv13 is V13 version of LocalDB, Both can now be used by VS2015 projects. Next, take mssqllocaldb as an example to connect. After a successful connection, the resource manager on the left side can manage the resources of the database.

Then we can try to create a new database test.

Once the test database has been successfully created, the database can operate normally. However, if you are connecting to an external database file, you cannot do so directly in SQL Server Explorer, and you need to do so in Server Explorer. The process is as follows:

Select Add Connection in Server Explorer, and if you connect directly to an external database file, the file is appended to LocalDB by default:

In the pop-up form, select Browse to add the external database file:

When you select a file and click OK, there is a connection to the external database file in Server Explorer:

Looking again at MSSQLLOCALDB in SQL Server Object Explorer, you can see that the external database you just added is attached to this local database:

At this point, the external database is attached, and if you want to connect to the database in your project, the connection string is as follows:

"Data source= (LocalDB) \\MSSQLLocalDB; Attachdbfilename= the absolute path to the external database file (note the escape character).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.