Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server / SQL-Server-2008R2

How to Resolve: The Data Source value in the connection string specifies an instance of SQL Server that is not installed or LocalDB instance does not exist

4.50/5 (4 votes)
21 Oct 2015CPOL1 min read 53.6K  
The error occurs when we try to create a new Microsoft SQL Server Database File (SqlClient) using Visual Studio IDE

Introduction

This tip will give you the resolution to the error which occurs when one tries to create a SQL Server Database File using Visual Studio IDE.

Background

This error occurs if wrong configuration is provided in Visual Studio IDE for the Datasource. This happens when we are creating a SQL Server Database File using Visual Studio IDE.

Image 1

Error

Error if mdg file is already present:

Image 2

Error if mdf file is new:

Image 3

Resolution

Check in your Program Files the Folder for SQL Server, it must be located in "C:\Program Files\Microsoft SQL Server". This can be also found in the Environment Variables => Path.

Image 4

Search for "LocalDB" in that folder, if you find the folder, that means SQL Server Express is installed on your machine.

SQL Server Express is a free edition of SQL Server which comes along with Visual Studio IDE. This has limitations though but is very handy to create file databases and query on them. For more details on SQL Server Express Local Db.

Go to the bin folder of LocalDB for e.g., "C:\Program Files\Microsoft SQL Server\110\LocalDB\Binn".

Go to command prompt => type =>

C:\Program Files\Microsoft SQL Server\110\LocalDB\Binn\SqlLocalDB.exe i

Image 5

You will get the names of the installed LocalDB. In this case, only one localdb is installed, i.e., v11.0. These names will be prefix for creating connection string using local db, e.g., (LocalDB)\v11.0.....

To resolve the issue in Visual Studio IDE, go to In your Visual Studio IDE, go to Tools => Options => Database Tools => Database Connections. The below screenshot shows that wrong LocalDb is used as datasource, so change it to the right one, i.e., one which is installed.

Image 6

Corrected one:

Image 7

Click on Ok and you are done. Now try creating the mdf file using Visual Studio and it should work.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)