Problem Background: The default database used by vs2012 is localdb. I have done a lot of Asp.net MVC exercises recently, especially when creating a project using the mvc3 (mvc4) Internet template, an account registration and logon function is provided by default, user data exists in localdb. In addition, many projects with databases created by myself will gradually accumulate a lot of databases in localdb. Of course, a self-created project may be just a demo. I think it is useless to delete it, and some will save it for use in a centralized manner. This produces two situations: first, the MDF file is deleted, but the MDF file path is changed. Today, I created a database connection in the project, and the server is still (localdb) \ v11.0. When selecting a specific database, it is found that too many optional databases are displayed in the drop-down list, many of which were abandoned a long time ago, which is really confusing.
Step 1: Go to the localdb command line tool. I tried to view all the databases in localdb and then delete the useless ones (about the basic usage of operating localdb in cmd ). The sqllocaldb.exe tool is used in runtime. View help (sqllocaldb /?), There are few available methods. Create, delete, and view the status of the current instance. Even databases under the current instance cannot be viewed, let alone deleted.
Step 2: I can't find a way to operate the database by using the command line tool. I hope some friends can give me some advice. I have tried database4.exe to connect to my localdb and try some operations. In it, I can graphically find all the databases on localdb. In fact, this tool is the same as creating a database connection in vs2012, but it just simplifies the operation. As mentioned above, many database names that I have deleted or changed the path will be displayed. Of course, if you want to open the database, a warning will pop up that the database file cannot be found. The operations can only be performed on objects at the database level, such as creating or deleting tables, there is still no way to delete the residual databases (which should be more appropriate for database references.
No, I hope the Daniel in the yard can give me some advice. In order to unify the problem with the subsequent solution, I decided to write an article. I am still searching for the answer, hoping to solve it as soon as possible ....
--------------------------- Subsequent updates ----------------------------
This evening, I asked my boss about the problem and solved it easily.
In the final analysis, I still haven't found the correct tool. Download an sqlserver 2012 express and install an SQL Server Management studio tool. The preceding database connection information can be deleted at will.