user
user

Reputation: 1351

Generate Code Map For Solution - Unable to Connect to the Specified Database

I am attempting to generate a code map using Visual Studio 2017 Enterprise, but receive the following error:

enter image description here

Note the data source: Data Source=(LocalDB)\MSSQLLocalDB. When I search for MSSQLLocalDB in my solution, nothing comes up. My application does not use SQL Server 2016 (which is what I think the connection string is for). It uses 2012. All my connection strings use (localdb)\v11.0.

Fixes I've attempted / notes:

enter image description here

enter image description here

Visual Studio is running on Windows 7 Ultimate, SP1, 64-bit.

EDITS

I am using SQL Server express with Local DB.

The issue does not appear to be related to connection strings. Following basic instructions for creating an SSDT project (here), and importing the database (noting that in step 6 I target SQL Server 2012), the issue still remains - no connection strings, and no actual code.

I have also verified that SQL Server 2012 is the only connected server: enter image description here

Error message added for SEO purpose (the question was not findable on search engines)

The XML content in this document cannot be viewed as a graph because it contains unexpected errors. Open the XML Editor to fix these errors and then try re-opening the graph. The actual error found is described below. Unable to connect to the specified database. An exception occurred attempting to connect to a database using the following connection string : Data Source=(LocalDB)\MSSQLLocalDB : Attach DbFilename=;Initial Catalog=master Integrated Security=True;Enlist=False;Asynchronous Processing=True; MultipleActive ResultSets=True Connect Timeout=30. Check that the specified SQL Server instance exists and the service is running. Call Stack : at Microsoft.Repository.SqlInteraction. OpenAndConfigureConnection (SqlConnection connection) Microsoft.Repository.SqlInteraction.<>c__DisplayClass7_0.<UsingConnection>b_0 () at at Microsoft.Repository.SqlInteraction.ExecuteRepositoryAction (Action action) at Microsoft.Repository.SqlInteraction. UsingConnection (SqlConnection sqlConnection, Action`1 act) at Microsoft.Repository.SqlInteraction. UsingMasterConnection (String connectionString, Action`1 act) at Microsoft. Repository. Utilities.GetDbStateAndFileNames (SqlConnectionStringBuilder builder) at Microsoft.Repository. Utilities.GetDatabase State (String connectionString) at Microsoft.VisualStudio. Architecture Tools. Progressive Reveal. PRUtilities. CanQuery (ActionContext context, IProgressionCacheSettings settings) at Microsoft.VisualStudio. ArchitectureTools. Progressive Reveal.GetRepositoryTimestamps Command.Execute (ActionContext context, IGraphStatus status Reporter, IProgressionCacheSettings settings) at Microsoft.VisualStudio. Architecture Tools. ProgressiveReveal. Progressive RevealProvider. GetRepositoryTimestampsHandler (ActionContext context) at Microsoft.VisualStudio. Progression. ActionManager. CallNormalActions (Action action, ActionContext actionContext, Boolean propagateCancellation)

Upvotes: 13

Views: 3087

Answers (2)

Piper
Piper

Reputation: 1109

I had the same issue with VS 2019. My solution was to delete and recreate the database MSSQLLocalDB. The cause was probably that my account didn't have rights to open the DB, maybe because my admin installed Visual Studio with his account.

Here the steps to recreate the DB:

  1. Locate the location of the SQL Server LocalDB utility. For me this is "C:\Program Files\Microsoft SQL Server\130\Tools\Binn\SqlLocalDB.exe".
  2. Open an admin shell in that folder.
  3. SqlLocalDB.exe i shows all database instances.
  4. Delete the DB: SqlLocalDB.exe d MSSQLLocalDB
    If this fails, you may need to try SqlLocalDB.exe stop MSSQLLocalDB -k first.
  5. Recreate the DB: SqlLocalDB.exe c MSSQLLocalDB

Now I can use VS code maps and I can open the DB in the SQL Server Object Explorer in VS.

Upvotes: 20

GraphWalk
GraphWalk

Reputation: 442

For me the solution was to delete folder c:\Users\u1\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB\ (stop 'sqlservr.exe' that locks this folder) - and it will be re-created (answer). Looks like this folder (or some file in it) was created by elevated process and neither VS nor sqllocaldb.exe can access it.

Upvotes: 2

Related Questions