Visual Studio Code Map: Unable to connect to the specified database

Have you tried changing your database name? You can use something like (Look at your appsettings.json file or web.config file)

<add name="DefaultConnection" connectionString="Server=YourDatasource;Database=DatabaseNameAsYouWish;Integrated Security=SSPI" providerName="System.Data.SqlClient" />

If you use SQL Management Studio, you will find the Data Source Connection string while you are connecting to the database. Copy and paste it, then try again. If it works, let me know, please.

Edit: Setup Connection String for ASP.NET Core 5 Web API Project

Step 1: For ASP.NET Core 5, in the appsettings.json file, put the connection string

"ConnectionStrings": {
    "sqlConnection": "Server=YourServerName;Database=YourDatabaseName;Integrated Security=true; Trusted_Connection=True;"
  },

(Note: If you want to use localdb, the connection string would be

"ConnectionStrings": {
    "sqlConnection": "Server=(localdb)\\mssqllocaldb;Database=YourDatabaseName;Trusted_Connection=True;"
  },

)

Where to find Server name?

  1. Open SQL Server Management Studio

Server Name

  1. In the Server name field, if you do not see the server name listed, click Browse for more...

Click Browse for more...

  1. Click the + sign next to Database Engine and you will see your Server name. Click on the server name and select it. Now connect to your SQL Server.

enter image description here

Now connect to your SQL Server.

Step 2. In the startup.cs add the service in the ConfigureServices(IServiceCollection services){ place your sql connectiono service here } method

// DatabaseContext comes from DatabaseContext.cs
            services.AddDbContext<DatabaseContext>(options => 
                options.UseSqlServer(Configuration.GetConnectionString("sqlConnection")) // sqlConnection comes from appSettings connectionString
            );

This worked for me:

Delete, Create, Start localDB instance used by CodeMap:

%localappdata%\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB

Using these commands:

sqllocaldb stop "MSSQLLocalDB" -k
sqllocaldb delete "MSSQLLocalDB"
sqllocaldb create "MSSQLLocalDB" 
sqllocaldb start "MSSQLLocalDB"

Then restart VS


Check out the difference between automatic and named (or private) LocalDb instances.

The support files necessary for v11.0 (SQL Server 2012) are probably no longer installed on your system. v12.0 indicates SQL Server version 2014.