SQL Server LocalDb ProjectsV13连接失败:已删数据库仍被请求
Got it, I've run into this exact issue before—when you delete the default database tied to your (localdb)\ProjectsV13 instance, SSMS keeps trying to connect to that missing MyDatabase, which blocks you from accessing the instance entirely. Here are a few reliable fixes to resolve this:
1. Connect to SSMS by Specifying the Master Database
This is the quickest temporary fix to get you into the instance first:
- Open SSMS, enter your instance name
(localdb)\ProjectsV13in the "Connect to Server" window - Click the Options >> button at the bottom-right, switch to the Connection Properties tab
- In the "Connect to database" dropdown, select
master(or type it directly if it's not listed) - Click Connect—you'll now be able to log into the instance normally
Once you're in, make sure to update your login's default database to avoid this issue in the future:
- Navigate to Security > Logins in Object Explorer, find your Windows authentication account
- Right-click it, select Properties, go to the General tab
- Change the "Default database" dropdown to
master, then click OK
2. Use SqlLocalDB & sqlcmd to Fix the Login Default Database
If even specifying the database in SSMS doesn't work, use the command-line tools:
- Open Command Prompt or PowerShell as an administrator
- First check the status of your LocalDB instance:
SqlLocalDB info ProjectsV13 - If the instance is stopped, start it first:
SqlLocalDB start ProjectsV13 - Connect to the instance using sqlcmd, explicitly targeting the master database:
sqlcmd -S "(localdb)\ProjectsV13" -d master - Once connected, run this SQL to update your login's default database (replace
YourWindowsAccountwith your actual Windows username inComputerName\Usernameformat):ALTER LOGIN [YourWindowsAccount] WITH DEFAULT_DATABASE = master; GO - Type
EXITto quit sqlcmd, then try connecting via SSMS again—it should work normally
3. Reset the LocalDB Instance (Last Resort)
If the above methods fail, you can reset the entire instance (warning: this will delete all data in the instance—only do this if you don't need any remaining databases):
- Stop the instance:
SqlLocalDB stop ProjectsV13 - Delete the instance:
SqlLocalDB delete ProjectsV13 - Recreate the instance:
SqlLocalDB create ProjectsV13 - Start the new instance:
SqlLocalDB start ProjectsV13
Now connecting via SSMS will default to the master database, and you can rebuild your databases as needed
内容的提问来源于stack exchange,提问作者Scott Software

