# Tuesday, 31 May 2005


So last night during the geek night session at the SDC, the Dutch, inspired by Richard Campbell called me on my SMO Backup and Restore GUI that had a progress meter. They thought I was hacking it, not that I was actually providing a true representation of the progress made by the status of the backup. Here is the progress meter in action, as the database backup makes progress we update the progress meter:




To do a backup programmatically you can to use SMO (see yesterday). Begin by setting the variables to get started.


Server svr = new Server();//assuming local server

Backup bkp = new Backup();


Cursor = Cursors.WaitCursor;


Then you have to set the device to backup to and what database to backup. Notice in the comments the code to the progress meter




      string strFileName = txtFileName.Text.ToString();

      string strDatabaseName = txtDatabase.Text.ToString();


      bkp.Action = BackupActionType.Database;

      bkp.Database = strDatabaseName;


      //set the device: File, Tape, etc

      bkp.Devices.AddDevice(strFileName, DeviceType.File);

      //set this when you want to do Incremental

      bkp.Incremental = chkIncremental.Checked;


      //progress meter stuff

      progressBar1.Value = 0;

      progressBar1.Maximum = 100;

progressBar1.Value = 10;


      //this gives us the % complete by handling the event

      //provided by SMO on the percent complete, we will

      //update the progress meter in the event handler


      //set the progress meter to 10% by default

bkp.PercentCompleteNotification = 10;

//call to the event handler to incriment the progress meter

bkp.PercentComplete += new PercentCompleteEventHandler(ProgressEventHandler);


//this does the backup


      //alert the user when it is all done

      MessageBox.Show("Database Backed Up To: " + strFileName, "SMO Demos");





catch (SmoException exSMO)





catch (Exception ex)







      Cursor = Cursors.Default;

      progressBar1.Value = 0;




Here is the ProgressEventHandler, notice that I made it generic enough that I can call it from both the backup and restore methods!


public void ProgressEventHandler(object sender, PercentCompleteEventArgs e)


            //increase the progress bar up by the percent

            progressBar1.Value = e.Percent;



posted on Tuesday, 31 May 2005 06:28:53 (Eastern Daylight Time, UTC-04:00)  #    Comments [1] Trackback
# Monday, 30 May 2005

The Software Developers Conference in the Netherlands has begun. Today I show how to prevent SQL Injection Attacks in ASP .NET as well as other cool tricks. Lots of RDs here and lots of happy attendees. As usual at SDC I will show something very new and cool. I will show off some of the new SQL Server Management Objects (SMO) in the keynote tonight. Ill give you a preview here.

The SMO object model is a logical continuation of the work done in SQL-DMO. SMO is feature-compatible with SQL-DMO, containing many of the same objects. . To achieve maximum data definition language (DDL) and administrative coverage for SQL Server 2005, SMO adds more than 150 new classes. The primary advantages of SMO are in its performance and scalability. SMO has a cached object model, which allows you to change several properties of an object before effecting the changes to SQL Server. As a result, SMO makes fewer round trips to the server, and makes its objects more flexible. SMO also has optimized instantiation, meaning that you can partially or fully instantiate objects. You can load many objects quickly by not instantiating all the properties of the objects. To get started you have to set a reference to it and pull in the namespace:

using Microsoft.SqlServer.Management.Smo;

Now I will show you how to programitically do a database restore. You start with getting the SMO objects: Server and Restore.

Server svr = new Server();

Restore res = new Restore();

Now take a look at how easy you can do a restore, just a few lines of code:

res.Database = “AdventureWorks“;

res.Action = RestoreActionType.Database;

res.Devices.AddDevice(“c:\mybackup.bak“, DeviceType.File);

res.ReplaceDatabase = true;


There is a lot more that you can do with SMO, but this shows you how easy it is to manage your server from code. A very cool thing to do it put some of the server monitor stuff into an ASP .NET page for viewing your server stats from a remote location.

More on SMO to come...


posted on Monday, 30 May 2005 07:32:15 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Saturday, 28 May 2005

That is the title of Richard and my Monday night keynote at the Software Developers Confrence in the Netherlands. Well I think it is now: “Estaban, splain dis Jukon to me!“ where we talk all about SQL Server 2005 in bad Spanish accents. To tell you the truth we have no idea what we are going to talk about, we do know that it will  be fun, contain beer and technical content. Confrences in the Netherlands rock.

Off to the Red Lights...

posted on Saturday, 28 May 2005 07:33:16 (Eastern Daylight Time, UTC-04:00)  #    Comments [1] Trackback
# Wednesday, 25 May 2005

At TechED 2005 US in Orlando, you will not want to miss the GrokTalks. Trust me. They break the mold and do not follow the MS party line. Stay tuned...

posted on Wednesday, 25 May 2005 17:12:06 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Monday, 16 May 2005

24 states have laws barring interstate shipments of wine. This is done to protect state industry. It is foolish. This means if I travel to Napa and visit a vinyard that is small they can't ship me wine unless they are “doing business in New York State”. Might as well move back to the Soviet Union.

Anyway, today the Supreme Court agreed with me and overturned a NY and Michigan law.

posted on Monday, 16 May 2005 13:29:05 (Eastern Daylight Time, UTC-04:00)  #    Comments [2] Trackback
# Thursday, 12 May 2005

Today at 2 p.m. Nepal time, Ed Viesturs, reached the summit of Annapurna. He has failed in the past, but by getting here he has become the first American to climb all 14 of the world's 8,000-meter peaks (and all without oxygen, having been there I know how hard that is!). In a call from the summit, Ed said that it's "one of the happiest days of my life, one of the hardest days of my life."

Congratulations Ed!

posted on Thursday, 12 May 2005 15:59:08 (Eastern Daylight Time, UTC-04:00)  #    Comments [104] Trackback