Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

If you like to migrate your Web tier or the ASP.NET Application to Windows Azure, check my new posts Part I and Part II

In the previous post we had examined on getting access to SQL Azure, creating your first database, accessing it with SQL Server Management Studio and then migrating the Northwind database schema to SQL Azure using the SQL Azure Migration Wizard Beta.

UPDATE: The latest version of SQL Azure Migration Wizard migrates both Data and Schema.  You can download the same from http://sqlazuremw.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32334

As explained earlier, the SQL Azure Migration Wizard migrates the schema of your database after tuning it for working with SQL Azure.  However, we would still need to migrate the Data to our SQL Azure Server.  At the moment, the step I took was to open the instnwnd.sql script in SQL Server Management Studio (SSMO) and copy the Insert statements alone to execute.  Note that, you cannot run all the scripts directly onto the SQL Azure portal like I explained earlier due to the limitations / formats supported currently in SQL Azure. 

To begin with, open “C:\SQL Server 2000 Sample Databases” folder (the default location where Northwind and pubs sample database gets installed) and double click on the instnwnd.sql script.  It opens up in SSMO.   Examine the scripts and navigate to the portion where the INSERT statements begin.  I took the portion and put it up as a single insert script.  You can download the script  from the link below:-

 

Running the scripts from SQL Server Management Studio

As explained in my previous post, open SSMO and cancel the initial login prompt.  Click on “New Query” and specify the server name as the fully qualified Azure Server name i.e. <YOURSERVERNAME>.ctp.database.windows.net, specify the user name, password.  Click on “Options” and specify “Northwind” at “Connect to database” option.  Click “Connect”.  It should be able to connect provided you have specified the path, username, password etc., correctly and created the “Northwind” database as per the previous post.  There will be a small error prompt that comes before opening the Query window, as below.  You can ignore that and click “ok”

 

image

 

Once you are in the SqlQuery1.sql screen you can check if the database is created and the tables are there by running  a bunch of few queries as below:-

SELECT * FROM Products

SELECT * FROM Orders etc.,

You will get blank result sets since we haven't migrated the data yet.

Double lick to open the insertnwnddata.sql script downloaded in the first step.  It would open in a new sql window.  Copy paste the script into the first window we got once we connected to the Azure Database.  If you get a connection error.  Try reconnecting using the “New Query” option as explained above.  If all is good, you should be able to execute the scripts.  Once the scripts are successful, you can test if the data is migrated, by again running the SELECT statements above.  They should now list data.   If there is an error, try running the individual INSERT statements for each table to verify which table has the issue.

Once this is done, we are all set to bind this data to our ASP.NET Page.

Binding the SQL Azure database to ASP.NET Page

Open Visual Studio 2008 and create a web application project.  In the Default.aspx page, drag and drop a GridView control and use the GridView’s wizard to connect to your local Northwind database.  Pick the Products table and chose the columns you want to display and complete the steps.  You may want to enable paging to avoid all data shown in the same page.

The above steps should add a GridView, a SQL Data Source to the page.  Once you run the website, it should display the Products table record with the columns you chose to display.  So far, we have bound the local database.  We however, intended to bind it to SQL Azure database that we have created.

Binding the GridView to the SQL Azure Database Table

If you thought this is another big process, you might be in for a surprise.  Visit the SQL Azure portal (https://sql.azure.com) sign-in with your credentials that you used to create the token/database etc., Click on the “Manage” link that comes in the right of the Configuration Page that you get once you sign-in.  The next screen lists all the databases created.  Click on the “Northwind” database radio button to select it.   Click on “Connection Strings” in the bottom (the one in the top gives the connection string for master, so click on the “Connection Strings” button below the grid that displays the databases.   You should get a popup with 3 different connection strings targeting different data access methodologies.  Chose the first one (Click on “Copy to Clipboard”) corresponding to the entry for ADO.NET (the first one). 

In Visual Studio, open the web.config file of the site that we created earlier and visit the connectionstrings setting.  If you had followed the wizard steps, it would have entered a connection string over here, that corresponds to your local database server.

Replace the connection string with the one copied here.  Note, you need to update the password that you used instead of “mypassword”.  Also, remove the trailing semicolon at the end after password. 

If you have done all the steps properly, you should be able to run the solution now and without any other change, the data that is bound to your grid view should display the same as it did when you initially bound it to the local database.  You can try paging / sorting etc., to see if all works fine. 

So, practically, we just had to change the connection string to be able to access the database on the SQL Azure Server.  From a developer’s perspective, the data access technique, binding, control and configuration remains unchanged.

That’s it for this series.  There are quite a lot of steps that I had listed over the last 2 posts.  You may want to check every point if you are facing any issue at any stage.

Cheers !!!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Print | posted on Tuesday, September 29, 2009 4:17 AM

Comments on this post

# web sit creating

Requesting Gravatar...
first time use of asp.net and creating the web sit now plz help me what are use in function for main tools
Left by krishna kant pandey on Sep 29, 2009 3:59 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
hi im in pune I love asp.net I need hlep do u have time to me
Left by feel on Sep 30, 2009 11:49 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
this didn't work for me...the sql script errors out on me...any ideas?

Thanks for putting this up.

Left by greg on Oct 13, 2009 3:42 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Let me see if I got this strait all my ADO.Net and Linq to SQL data access code I have in an existing app will work I going to give this a try this weekend it will be a victory or a sleepless weekend Azure is big and the sky is the limit great stuff keep the articals comming good stuff
Left by rickj1 on Dec 18, 2009 6:00 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
I've followed all the steps when I try to access with managment studio I get this error
Client with IP address xxxx.xxxx.xx
is not allowed to access the server If allowed port 1433 Ive added this IP address through the fire wall this new rule is not showing up is not showing up in my server admin page
Left by rickj1 on Dec 20, 2009 8:22 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Your work is very good and I appreciate you and hopping for some more informative posts. thank you for sharing great information to us
Left by UK Web Host on Mar 09, 2010 11:41 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.
Left by Andersen Windows on Mar 11, 2010 1:38 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!
Online Public Administration Degree | fire science degree
Left by Online Law School on Mar 18, 2010 10:00 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Thanks for sharing. i really appreciate it that you shared with us such a informative post..
Nursing degree | social service degree
Left by Mark on Mar 18, 2010 10:01 PM

# # re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
From a developer’s perspective, the data access technique, binding, control and configuration remains unchanged.
Left by Infrapunasaunan rakentaminen on May 02, 2010 4:12 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Hi. I wanted to drop you a quick note to express my thanks. I've been following your blog for a month or so and have picked up a ton of good information as well as enjoyed the way you've structured your site. I am attempting to run my own blog but I think its too general and I want to focus more on smaller topics. Being all things to all people is not all that its cracked up to be.
Left by Gray water on May 02, 2010 5:51 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work.
Left by acne treatment on May 03, 2010 4:16 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Hi,
I have the sql script errors for me, this didn't work for me...
Have you any ideas for that?

Thanks for the great post.
Left by kabbalah bracelet on May 12, 2010 1:25 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Your work is very good and I appreciate you and hopping for some more informative posts.
Left by Acnezine reciews on May 18, 2010 5:35 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Hello, I am a student studying research database. Hope your site to learn new knowledge.
You mentioned the issue of migration of the database.Will the site's database server replacement, and now need to program point to the new server address, but I do not know in which file changes,and how to amended?
Left by ipad apps download on May 31, 2010 9:59 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
That’s it for this series. There are quite a lot of steps that I had listed over the last 2 posts. You may want to check every point if you are facing any issue at any stage.
Left by nannce on Jul 11, 2010 6:44 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Your Steps of SQL Azure Server is amazing. It is quite easier then SQL Server 2005. More over Scripts you given was very helpful.I belive that this site is most useful for students and those who wanna be expert in Database Handling.
Left by Muscle building on Jul 13, 2010 7:50 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
This is very good but I want to have both related tables displayed a Details view not just one as a details view and one as a gridview. I want my users to enter data into my form without having to drop into another section.

I personally believe this is impossible (although I was able to do it with MS Access by writing it as a query. I don't know how to do this in Visual Studio)There are absolutley no "How To's" on this problem and feel this is a huge downfall of what forms are supposed to be all about.
Left by sexy lingerie manufacturer in ch on Jul 30, 2010 12:09 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
you can replace the connection string with the one copied here. Note, you need to update the password that you used instead of “mypassword”. Also, remove the trailing semicolon at the end after password.
Left by Refrigerator service on Aug 19, 2010 11:05 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Open Visual Studio 2008 and create a web application project. In the Default.aspx page, drag and drop a GridView control and use the GridView’s wizard to connect to your local Northwind database. Pick the Products table and chose the columns you want to display and complete the steps. You may want to enable paging to avoid all data shown in the same page.
Left by Viking refrigerators on Aug 21, 2010 3:24 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
n Visual Studio, open the web.config file of the site that we created earlier and visit the connectionstrings setting. If you had followed the wizard steps, it would have entered a connection string over here, that corresponds to your local database server.
Left by How to stain wood on Aug 31, 2010 11:36 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
I'll attempt this over the weekend. Thanks for the info
Left by Vladimir on Sep 23, 2010 2:25 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Hello I am so delighted I found your blog, I really found you by mistake, while I was looking on Yahoo for something else, Anyways I am here now and would just like to say thanks for a tremendous post and a all round entertaining blog. Please do keep up the great work
Left by newest jordan shoes on Oct 20, 2010 2:05 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
SQL data is cool.
Left by Mannatech LIFT on Feb 21, 2011 8:05 AM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Valuable work you are doing here - thanks!
Left by canvas prints on Feb 28, 2011 4:48 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
You are doing great job here. Well done:)
Left by Ionic Breeze on Apr 27, 2011 11:09 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
good topic man. i will be coming to this web site on regular basis. keep it up.
Chatroulette , Chatroulette
Left by ron on May 26, 2011 5:21 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
I found the perfect place for my needs. Contains wonderful and useful messages. I have read most of them and has a lot of them. To me, he’s doing the great work.

Home Buyer Rebate
Left by poul on May 26, 2011 5:24 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
Interesting post and thanks for sharing. Some things in here I have not thought about before. Thanks for making such a cool post which is really very well written. will be referring a lot of friends about this.Keep blogging
Benchmade
Left by poul on May 26, 2011 6:04 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
LongPack is your preferred Shanghai China printing partner that specializes in Paper box, Book Printing and china catalogs. An organization where we learn about the manufacturing process of board games and we never compromise on quality providing services that are superior to our competitors.
gift bags china
Left by china printer on Nov 07, 2011 3:02 PM

# re: Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

Requesting Gravatar...
We are always moe. Thank you.
Left by moe on Jan 31, 2012 8:10 PM

Your comment:

 (will show your gravatar)