Migrating and Deploying a Simple Cloud App: Part 2 - Scripting the On-Premise Database For SQL Azure
If you’ve started reading from this post, you’ll need to go through the previous parts before starting this one:
Introduction
Part 1: Setting Up a SQL Azure Server and Database
In this part, we’ll take our application’s on-premise database and script it for SQL Azure.
Attach the SQL Server Database
Unzip the Nerd Dinner zip file you downloaded.
If you haven’t yet downloaded Nerd Dinner, download it from here.
Locate the App_Data directory. You’ll notice there are 4 files. Two .mdf files and two .ldf files.
We’re only going to need NerdDinner.mdf and NerdDinner_log.ldf.
Copy NerdDinner.mdf and NerdDinner_log.ldf to your SQL Server’s data directory. If you don’t have access to a SQL Server but you have SQL Express installed, that will do as well.
Open SQL Server Management Studio and open a connection to you SQL Server.
You can download SQL Server 2008 Management Studio Express from here if you don’t already have the full SQL Server 2008 Management Studio.
If you’re using SQL Express, the server name will most likely be localhost.
Right-mouse click on the Database node and select Attach. The Attach Database screen will be displayed.
Click on Add.
Locate NerdDinner.mdf in the list and select it.
Click OK.
Click OK once more to attach the database to your SQL Server.
Right-mouse click on the Databases node and select Refresh. Look for C:\USERS\JON\DESKTOP\NERDDINNER_2.0\NERDDINNER\APP_DATA\NERDDINNER.MDF.
Unfortunately, the name that was originally given to the database is preserved. That’s why the name is so long and doesn’t just display as NerdDinner.
Producing the Script
Now that you’ve found the NerdDinner database, right-mouse click on it, select Tasks, and then select Generate Scripts.
Click Next on the first step of the Generate and Publish Scripts wizard.
Before we produce the actual script file, we need to tell SQL Server Management Studio that we will be deploying the script to SQL Azure. Click on Advanced.
Scroll down and locate Script for database engine type. Change the type to SQL Azure Database.
Click OK.
Now the script has to be saved. Click on … located to the right of File name.
Find the directory where you’d like to save the file, give it a file name, say NerdDinner.sql, and click Save.
Save the file in an easily accessible location such as your desktop. You should delete the script file after you deploy it in part 3.
Click Next and Next again to begin scripting.
When all the tasks have completed, click Finish.
Detach the Database
The on-premise version of the NerdDinner database will no longer be needed. We can now detach it from our SQL Server.
Locate the NerdDinner database.
Remember, it has a long name and is all in capital letters.
Right-mouse click on the database, select Tasks, and the select Detach.
Place a check mark under Drop Connections.
Click OK to detach the database.
That’s all it takes to convert a SQL Server on-premise database to a SQL Azure cloud database! Depending on the complexity of your future applications, you may have to do some more tweaking once the script is created. There are some features of SQL Server that are not supported by SQL Azure, and as such, you’ll have to remove them from the produced script. The database for this walkthrough is intentionally simple, so no further tweaks have to be made.
Next up – executing scripts on the SQL Azure database.
Comments
- Anonymous
March 27, 2011
Regarding the use of SQL Server Management Studio, note that SQL Server 2008 R2 is required to have access to the Azure-related features.