2

I found the following link

Installing the Northwind Sample Database

However I am still not clear on the process. This talks about Server 2000 and MSDE 2000 but what I need is for the new SQL Server Local DB.

Has anyone else had to do this and found any instructions on how to proceed?

  • are you using SQL SERVER 2008...? and you have Northwind.mdf file...? – Pandian Mar 14 '13 at 07:31
  • I am not using SQL Server 2008. I am using the new SQL Server Local DB that comes with VS2012. I don't yet have the Northwind.mdf file. –  Mar 14 '13 at 07:33
  • Northwind is a sample DB given by MS, You first download it.... Before that refer the below link : http://stackoverflow.com/questions/5061629/where-can-i-find-the-northwind-database-for-microsoft-sql-server-2008 – Pandian Mar 14 '13 at 07:41

2 Answers2

11

So, I can't seem to find a way of attaching an existing DB file to a LocalDB instance from inside visual studio (creating a new DB seems to be the only option), but you can do it via management studio by doing the following:

Step 1 - Find out the instance name of the LocalDB

Open a command prompt and run (the location may be slightly different depending on your install location):

C:\Program Files\Microsoft SQL Server\110\Tools\Binn>SqlLocalDB.exe info

This will list all the instances of LocalDB, find the one you're interested in, VS2012 installed one for me called v11.0 (which I will use for my example)

Step 2 - Start the LocalDB instance

Again in your command prompt run the following:

C:\Program Files\Microsoft SQL Server\110\Tools\Binn>SqlLocalDB.exe start v11.0

This will start the LocalDB instance and allow us to get the connection info

Step 3 - Get the name of the named pipe to connect to (pipe name changes every restart)

Another command prompt job:

C:\Program Files\Microsoft SQL Server\110\Tools\Binn>SqlLocalDB.exe info v11.0

This will then return information about the instance, including the following line:

Instance pipe name: np:\.\pipe\LOCALDB#A6F550C6\tsql\query

Step 4 - Connect via management studio and attach the database

Open management studio and in the server box connect to the named pipe (windows auth) e.g. :

\.\pipe\LOCALDB#A6F550C6\tsql\query

You will now be in the SQL server like it was a normal instance, you can copy your Northwind MDF file to the data directory of the instance (mine was the root of my user folder) and then in the databases node in the management studio right click and select attach, select the MDF file and then attach as normal.

Hope this helps.

steoleary
  • 8,968
  • 2
  • 33
  • 47
1

How about just restoring via SSMS using Steps:

  1. Download northwind (https://northwinddatabase.codeplex.com/) and save .bak somewhere
  2. Open SSMS
  3. Connect to (localdb)\ProjectsV12 (or whatever version you have)
  4. Right Click Databases Node (see image)
  5. Select Restore...

enter image description here

  1. In Restore Database window, Source | choose 'Device' radio button and in drop down 'Backup media Type' choose File and then click 'Add' button browse to location of downloaded .bak file

enter image description here

  1. That's it, your .bak should be loaded to a new database on your machine.
yonsk
  • 163
  • 1
  • 8