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.
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.
Error if mdg file is already present:
Error if mdf file is new:
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.
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
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.
Click on Ok and you are done. Now try creating the mdf file using Visual Studio and it should work.