You would have thought in these days of point and click a simple task like copying a database from one place to another would be a walk in the park. So when I wanted to take a copy of a SQL database from Azure and move it to my local machine, I thought it surely would be straightforward. It’s not. Here’s what I came up with:
In Azure make sure you have a Storage account set up, with a container inside. My container is called ‘files’.
Image may be NSFW.
Clik here to view.
In Azure go to your database. Click the Export button down the bottom.
Image may be NSFW.
Clik here to view.
A new window will pop up. The file name will probably be pre-filled. Select your blob storage account (if you only have one then it’s already selected). Select a container (mine is ‘files’). Enter your SQL Server log in name and password – these are the credentials you set up when you added the database. Click OK and the export should start – you’ll see the status down the bottom.
Image may be NSFW.
Clik here to view.
Once the export is done, you can click to view your Storage container, and you should see the export file there.
Image may be NSFW.
Clik here to view.
The trick now is to get the file from Azure to your local machine. I use Azure Storage Explorer, it’s a free download. Download the file from your container.
Image may be NSFW.
Clik here to view.
If you have SQL Server 2012, then you are home free, because you can import the BACPAC file in SQL Management Studio. Right click on the Databases folder under a server in the Object Explorer and choosing “Import Data-tier Application.
If like me you are on SQL Server 2008 R2, you need some help.
Create a new blank database on your local machine.
Go to http://msdn.microsoft.com/en-us/jj650014 and install the SQL Server Data Tools for Visual Studio 2010. After install go and find SqlPackage.exe, I located it in C:\Program Files\Microsoft SQL Server\110\DAC\bin. Open up a DOS prompt and use the following command:
SqlPackage.exe /a:Import /sf:c:\Desktop\FILENAME.bacpac /tdn:DATABASENAME /tsn:SQLSERVERNAME
- FILENAME.bapac is the file you downloaded from Azure, whereever it is located on your machine.
- DATABASENAME is the name of the new blank database you created a minute ago.
- SQLSERVERNAME is the name of the SQL server on your local machine.
I followed these steps, albeit for a fairly small file, and it worked perfectly.
Filed under: Geeky, Programming, Web/Tech Tagged: Azure, BACPAC, Data Export, Data Import, SQL Server Image may be NSFW.
Clik here to view.
