Nick 879
Nick 879

Reputation: 130

Can't access a Visual Studio database in SQL Server Management console

I have created a SQL Server database in Visual Studio 2017 Community edition. I can see it in "Data Connections", and it works fine. I can view and edit tables in Visual Studio without any problem.

enter image description here

I can also see the physical file in Windows file explorer. However, when I try and look at it in SQL Server Management Studio (or Power BI), the applications can't seem to find it. The Management Studio seems to think I have multiple instances of SQL Server Express available, but none of them list my application database as being present.

enter image description here

For example

enter image description here

Can anyone put me on the right track as to how to connect this database to SQL Server Management Studio.

Sorry if it's obvious, but I've spent a couple of days on this, and I'm ready to beat my head against a wall.

Any help gratefully received.

Upvotes: 0

Views: 1047

Answers (1)

Shekar Kola
Shekar Kola

Reputation: 1297

Check the properties of data connection to identity into which SQL Instance the database being saved/deployed from VS.

The management studio seems to think I have multiple instances of SQL Express available, but none of them list my application database as being present

The tool cannot think/recognize of something not installed, either you might have connected the listed SQL Instances earlier or they installed locally. you can identity all installed SQL Instances via SQL Server configuration manager.

Deepening on version you can open SSCM via run command (following) from windows:

  • SQL Server 2017: run --> SQLServerManager14.msc
  • SQL Server 2016: run --> SQLServerManager13.msc
  • SQL Server 2014: run --> SQLServerManager12.msc

Seems your database saving at SQLLocalDB instance which is light version of SQL Engine, doesn't required any service installation. The regular method of connecting database server would not work in Local DB case, you must follow these steps, and these steps for details

In case if the development has been done, and you want work with same database on SQL Express instance, you can use attach method to bring database into one of SQL Instance, following steps would help to do that:

  1. Connect anyone of existing SQL Express instance
  2. Close VS to release active connections on Investments 4 copy.mdf
  3. Copy .MDF into desired location where you want the data storage to be
  4. Open new query window from SQL Express Instance connection (which is done in step1), execute following query, or you may follow these steps(GUI)..
CREATE DATABASE YourDBName
      ON (FILENAME = 'D:\CopiedLocation\CopiedFile.mdf')
FOR ATTACH_REBUILD_LOG ;
GO

Upvotes: 1

Related Questions