Migrating my local SQL Database to Azure SQL (again)

I didn’t complete it

In my previous attempt to get my local SQL Server MediaLibrary into Azure, I left it incomplete. I truly didn’t realize that until I tried to connect SQL Server Management Studio (SSMS) to my database in Azure. It connected, but there was no data in any of the tables. My bad.

So let’s get this right. First, I deleted the database in Azure SQL. I don’t know if it is possible to do it any other way, but since it’s a small enough database I thought that would be all right. That and when I tried to upload it straight from SSMS, I got error messages about incompatibility. So in order to resolve this I decided to delete the previous instance from the Azure portal, to start over again. To do this I returned to the MSDN article SQL Server database migration to SQL Database in the cloud.

Starting Over Again

There are three steps you must take in order to migrate your local SQL database into Azure, they are:

  1. Test for compatibility
  2. Fix compatibility issues
  3. Perform the migration

I decided to use SQL Server Data Tools for Visual Studio (SSDT). This is for testing for compatibility. That led me to a link titled Migrate a SQL Server Database to Azure SQL Database using SQL Server Data Tools for Visual Studio.

WOW, in going through this I’ve discovered what step I left out. Its towards the end under “Fixing Compatibility Issues Using SQL Server Data Tools for Visual Studio”. I stopped short of doing step #4 which is updating the local target V12 compatible database and actually publishing the original data to the V12 compatible database.

(Someone, I can’t remember who nor where, asked me for my feedback on where in the Microsoft Azure documentation, did I leave off accidentally. I’m sorry, I can’t remember who you were, but it is here, in this Migrate a SQL Server Database to Azure SQL Database using SQL Server Data Tools for Visual Studio. I think it was because this article, to me, seemed to suggest that if I followed this article, I’d be done. I was mistaken in my interpretation, that is clear. And it was before this point where I stopped previously.)

Step 5 is a link back to Migrate a compatible SQL Server database to SQL Database. So I’m returning to the that article to select a migration method.

Migrating my SQL Server compatible database to Azure SQL

Because of my local video library database is small and I can control activity to it, I’m going to use the SSMS Migration Wizard. Selecting the link to migrate my compatible database I went to a page titled Migrate SQL Server database to SQL Database using Deploy Database to Microsoft Azure Database Wizard.

After getting back in SSMS I right mouse button clicked on the new V12 compatible database I created locally, and selected “Deploy Database to Microsoft Azure SQL Database” option under Tasks. That brought up a wizard to walk me through deploying the database.

At this point I started entering my Azure credentials, this time selecting a different name for the target database in Azure (just in case). I noticed that for the temporary file name the wizard is creating a .bacpac file. Interesting. So one way or other a BACPAC is used to perform the migration.

I’d like to point out that at this step the dialog box that I got for entering my initial credentials, didn’t look like what was in the article. Here’s what mine looked like:

Initial Publish Database screen

The instructions at step 6 talk about naming the database, setting the edition of Microsoft Azure SQL database, max database size, etc. Because this is an experimental database that I alone will be hitting against (maybe some of my family members will use it later on when I get to the point of writing an app to hit against it – I’ll blog about that as well), I am choosing Basic Edition, 2 GB of database size (that’s the max for basic anyway) and Service Objective of Basic.

Deploy Database screen

Clicking the Next button takes you to a summary. And here I can click on the Finish button which actually performs the migration of the database and data, into Azure SQL.

And here’s what the Deployment Settings window looked like:

Deploy Database screen

Verifying it worked

While still in SSMS I used Object Explorer to connect to my Azure SQL database to just make sure it worked.

It worked!


My Review of the Microsoft Band 2

It has nice features, but the battery life is very poor.

I got my Microsoft Band 2 in 8 months ago. I like the features that it has, especially after they added the Explorer tile.

However, the battery life on these Band 2 are so poor as to seriously detract from it. My first Band 2 began to need to be recharged in under 24 hours. Then it went even lower. It got so bad that I decided to get a replacement. I’ve been using the replacement for less than 2 months and it is even worse. It now goes dead in under 8 hours. I’m charging it twice a day. Its on the charger more than its on me. This is unacceptable. Reluctantly I have to say that I do not recommend the Band 2.

Finally Got My Database into Azure!

I’m very pleased to say that I’ve finally gotten my local SQL Server database into Azure SQL!! The MSDN article that really helped was using this one titled SQL Server database migration to SQL Database in the cloud. This article lists various ways in which you can migrate you SQL Server database into Azure. (Note: it also references other types of databases.)

One of these methods was to use SQL Server Data Tools (SSDT), which I’ve got experience at using, so I decided on that one. The link to SSDT led me to a page titled Migrate a SQL Server Database to Azure SQL Database Using SQL Server Data Tools for Visual Studio. I found this to be very helpful!

Following the instructions on that last link I created a project in Visual Studio (using SSDT) to detect SQL Database V12 Incompatibilities. I had some V12 incompatibles (really, no surprise), but again following that last link’s instructions I eliminated the incompatibles.

Next I published my (slightly modified) database schema and data into Azure. At this point I created a new database and published it there. It asked me to create the firewall rules (this is where I specified my IP address). I’ve got it up there and have looked at the data through Visual Studio.

Learning Azure SQL

Recently I decided that I wanted to stretch myself by learning some new technologies. The “cloud” has been around for a few years now, but I haven’t yet used it, at least from a developer’s point of view. So I’ve decided to start with Microsoft’s Azure. I’m going to chronicle my learning experience here, if for no other reason than I’ll have something to refer to in the future. Smile

Since I’m doing this on my own, mostly on the weekends and whenever I can sneak in 30 minutes some weekday evening, I’ve had to ask around to learn how to do it. It was recommended to me that I take something I’ve used in the past and upload it to Azure. Years ago I started a SQL Server database at home, so that I could learn new (to me at least) technologies. (I used this to help me learn ASP.NET and WPF/XAML.) This database is for our fairly extensive DVD (and now Blu-ray) collection. I called it MediaLibrary.

The first thing I had to decided was how to get my MediaLibrary into Azure. I asked around and got two suggestions. First, I could create a VM in Azure, install SQL Server into it and upload my database into it. (What I believe is called Platform as a service, or PAAS.) This idea attracted me at first, but others suggested that doing this I really wouldn’t learn anything new. They recommended that I learn Azure SQL instead. (Infrastructure as a service, or IAAS.) So that’s the approach I’ve decided to follow.

A Useful Tutorial on Getting Started with Azure SQL

The first big help I got was to go to a link for a tutorial on how to do this, titled SQL Database tutorial: Create a SQL database in minutes using the Azure portal. I’m finding this to be a very helpful tutorial so I highly recommend it.

Single IP vs. Range of IP Addresses

Being a novice at this there are some obstacles I’ve run into. I read through the tutorial before starting. The first thing I ran into right away was where it said, “Create a server-level firewall rule for a single IP address or for a range of IP addresses.” Again I asked about this and was told that either I could get a static IP address or I could ask my ISP for the range of IP addresses they have. I thought that my ISP would have a huge range of IP addresses and I certainly didn’t want someone else potentially getting to my database in Azure, so I’ve decided to get a static IP address from my ISP. If you’re following this blog post, you have to make your own decision in regards to this. For myself I thought the static IP would work best.

Next Steps

Next I created a new SQL Server (logical server). As I understand it now, this is a place where a Azure SQL database can be put. You need this first before you can go on. When I entered all of the information required (see the link above to the tutorial) it took about 5 minutes to create after I clicked the Create button.

Next I went to create the Azure SQL database itself. This is as far as I’ve gotten. I’m now at the section titled, “Create a new Azure SQL database”. Where I’ve gotten stuck is selecting the source. The Select source dropdown has three options: Blank, Sample or Backup. I don’t want a blank database, as I’ve already got one. I don’t want a sample like AdventureWorks. Really the best choice for me is Backup, because I’ve backed up my MediaLibrary database. However this is where I’ve gotten stuck; selecting Backup makes Azure look only at itself for the backup. At least that’s the idea I’ve gotten. It certainly doesn’t give me the option to upload my .bak file. So, until I learn what I’m supposed to do next, I’m stuck. Hopefully I’ll learn later today. I’ll post after that.

C#’s HashSets

One thing that you encounter whenever you interview for a position as a .NET developer the technical question. That can make many forms, such as the famous “fizz-buzz” puzzle. But one that has always stumped me is how to find common elements between two arrays of the same data type. I’ve always come up with using two loops, one within another, which is of type O(n2). In the .NET framework I’ve recently learned of HashSets, which are extremely cool. This makes finding common elements easy. To learn more about them I decided to write a simple console app to try it out. This is based upon the MSDN online article on HashSets, which I’ve expanded upon. Here’s the source code:

using System;
using System.Collections.Generic;
using System.Linq;
namespace SimpleHashSet
class Program
static void Main(string[] args)
Console.WriteLine("Learning about HashSets\r\n\r\n");
HashSet<int> setA = new HashSet<int>();
HashSet<int> setB = new HashSet<int>();
for (int i = 0; i < 5; i++)
setA.Add(i * 2);
setB.Add(i * 2 + 1);
//now, just add 100 to both
Console.WriteLine("setA contains {0} elements:", setA.Count);
Console.WriteLine("setB containts {0} elements:", setB.Count);
//what is the intersection?
HashSet<int> theIntersection = new HashSet<int>(setA);
Console.WriteLine("Using the Intersect method on setA with setB");
//what is the intersecion with about?
HashSet<int> intersectWith = new HashSet<int>(setA);
Console.WriteLine("Using the IntersectWith method on setA with setB");
//what about the union method?
HashSet<int> theUnion = new HashSet<int>(setA);
Console.WriteLine("Using the Union method on setA with setB");
//what about the UnionWith method?
HashSet<int> unionWith = new HashSet<int>(setA);
Console.WriteLine("Using the UnionWith method on setA with setB");
//what is the Except method all about?
HashSet<int> theException = new HashSet<int>(setA);
Console.WriteLine("Using the Except method on setA with setB");
//now try the ExceptWith method
HashSet<int> exceptWith = new HashSet<int>(setA);
Console.WriteLine("Using the ExceptWith method on setA with setB");
//this is the end
Console.WriteLine("\r\n\r\nPress any key to quit.");
private static void DisplaySet(HashSet<int> passedSet)
foreach (var item in passedSet)
Console.Write(" {0}", item);
Console.WriteLine(" }");
If you run the preceding code you’ll get this in the command window:
Don’t know about you, but I find things like this handy to use a refer back to.