I'm sensing some battle lines being drawn

I’ve gotten my hands a little more dirty with SQL 2005 over the last couple of months. I’ve used CLR triggers and stored procs to implement some functionality that would have been difficult to do using T-SQL. I’ve worked with XML datatypes to generically extend the fields that can be persisted in a table. In other words, I’ve played with some of the newer and potential more contentious features of SQL 2K5.

While cruising through a number of blogs today, I came across this post from Don Demsak. In it, he refers to an eWeek article DBAs Bar Door Against Big Bad .Net Wolf.

My own experiences suggest that this tone is just the beginning. I recently had a chance to hear a presentation on the Web Service functionality that SQL Server provides. For the uninitiated, it is possible to define an HttpEndpoint in SQL Server. On this endpoint, methods can be defined that expose stored procedures. Interesting functionality to include in SQL Server, but what I found most interesting was the angle that the speaker took in support of the idea of exposing your SQL Server machine to the Internet. The suggestion was that, with ASP.NET Web services, the DBA has no idea what data or functionality that the ignorant (my word, but their tone) developer created. By exposing their own Web services, the DBA could take control over the exposed data by eliminating the middle man.

My first instinct was ‘whoa’. The approach seemed a little extreme. Maybe I’m just an ignorant developer, but for most of my professional life, the idea of having the machine running the database server exposed to the Internet, even if it was ‘only’ port 80, was never considered a good idea. And the HttpEndpoint doesn’t include support for any of the WS-* standards. It is basically just the same sort of Web service that was available back at ASP.NET 1.0 before the introduction of WSE.

Does anyone else thing this feature is a good idea?  Am I just being short-sighted and/or narrow-minded?

Metro Toronto .NET User Group Meeting September 8th: Managed Code in Sql Server 2005

On September 8th I'll be speaking at the .NET User Group here in Toronto. I'll be talking about how developers can take advantage of Sql Server 2005's ability to host managed code. Full abstract and registration details are here.

EXECUTE permissions needed for XML Schema Collections

I’m working in depth with the new XML data type in SQL 2005 for the first time. There are a number of aspects that I really like. In particular the ability to strongly type the column using an XSD as the validation. For what I’m doing (it involves allowing a client to extend and persist database tables), they are almost perfect.

As you work through this process, however, it’s important to be aware of the permissions that are required to utilize the schema. Once I had added my XSD to the XML Schema Collection, I tried to INSERT a record into the table. I received the following exception:

System.Data.SqlClient.SqlException: EXECUTE permission denied on object 'OrdersExtension', database 'Northwind', schema 'dbo'

It turns out that in order to use the schema, the user needs to be granted EXECUTE rights. Specifically, the following statement needed to be executed:


Whoo-hoo.  Problem solved.

Document Outline for Windows forms

Many of you may be familiar with the Document Outline feature in word. Did you know Visual Studio also has a Document Outline. It's there in VS 2003 for Web Forms, in 2005 MS has made it useful to windows developers also.

To open the Document Outline window goto View | Other Windows | Document Outline or Ctrl-Alt-T.

Some things you can do with the Document Outline Window.

  • See a list of all your controls
    • This is not just a list though, it's a nested view of your form via treeview. Showing what container each control is in. This is a useful way to view a complex form. Any windows developer will tell you sometimes a form gets complicated and it's difficult to get a good picture of what is going on with splitters, panels, tabs etc.

  • Select controls to change their properties
    • We have all done it; clicked on a control on a form and inadvertantly moved it. With the Document Outline you can select a control so that you can use the property explorer without actually touching the form. You can also do this in the property browser itself using the list box at the top but it's easier to select the control from the Document Outline Window, because you can see all of them at once. If anyone from MS is reading this I would like to be able to multi select controls from this window.
  • Move controls from one container to another
    • One very cool feature is being able to move control from one container to another using the Document Outline. for example; you can drag a control from one side of your Split Container to the other or from a panel to the form, right in the Document Outline window. This can be very useful on a complicated form with many controls.

I'm not sure how much I will use this window once developing on a regular basis with it. But I can think of a few projects it would have come in handy.

Snap Lines

I know snap lines are not a big deal especially when you look at all the other new features of Visual Studio 2005. But for a windows developer they are a welcome productivity tool.

I'm not blogging to tell you 2005 will have snap lines. I'm blogging to show you this cool feature of snap lines.

Lets take a label and a textbox for example, this is likely where they will come in the most useful. Being able to visually line these two controls up is a real time saver.

Did you know you can also line up the text in the label with the text in the textbox.

Now that is nice.

Ridding yourself of the Print Status Dialog

I had the need this past weekend to eliminate the Print Status dialog from a printing process. Just to make sure that we’re speaking the same language, the Print Status dialog is that message box-like artifact that appears while a job is printing. The text in the dialog shows progress with a ‘Printing 1 of 10’ sort of message. It is this generic message that I was trying to get rid of.

Research into this area introduced me to a class that I was previously unaware of – the PrintController. This class is responsible for driving the printing process, detecting when the process has been cancelled and raising the PrintPage event. As such, it is also in charge of displaying and updating the print status dialog.

There are a number of classes in the .NET Framework that provide print controller functionality. The StandardPrintController actually doesn’t display the Print Status dialog, so it is a simple process to instantiate a StandardPrintController object and assign it to the PrintController property on the PrintDocument. Now that annoying (to me, anyway) goes away.

Or does it. All is good until you want to preview the document. Setting up a PrintPreview dialog and activating it results in that Print Status dialog reappearing. Even after the StandardPrintController is being used. Nothing I try makes the message box go away. Some in depth digging reveals the cause of the problem. Deep in PrintPreviewControl class there is a method called ComputePreview. The purpose of ComputePreview seems to be to generate the entire report and make it available for previewing. Within this method, the PrintController property on the PrintDocument associated with the preview control is temporarily replaced. Replaced, it turns out, with the PreviewPrintController. And the PreviewPrintController displays the print status dialog. To this point, I can’t seen how to avoid this problem. Any suggestions are welcome.

Unexpected Locking in SQL Server 2005

I was working a little bit with SQL Server 2005 today and ran across an unexpected (at least to me) situation. From within the Management Studio, I opened up a table to view the contents.  Nothing complicated, although I did modify the default SQL slightly to reorder the results.  Then, in another query tab, I executed a script that did a DROP TRIGGER against the table that I had just opened. Problem is, the DROP statement just hung there. Waiting on a lock.  Specifically, waiting on exclusive access to the table. A lock that it couldn’t get because I had opened the table through Management Studio. Like I said, unexpected.

The solution was simple once I saw who was holding the lock. Close down the tab and everything was hunky-dory.  But the time I spent researching the problem is gone, never to be recovered. I also did a bit of digging into why this was so unexpected. It doesn’t appear to happen in Enterprise Manager. Simply opening a table and retrieve all of the rows does not establish a lock on the records. Doesn’t even appear to if you start to edit a particular record. Chalk it up to one more thing that is new and improved.


Updating Config Files in ASP.NET 2.0

One of the new features of ASP.NET 2.0 is the ability to not only more easily read from config files, but also to update them. If you’re looking for a pretty good description of what’s possible, check out the ASP.NET QuickStart Tutorial. Going over the basic process isn’t the point of this post. Instead, I want to talk about an unexpected, but yet expected, side effect.

The situation is quite common. Your web site utilizes Session variables. Over the course of your application, you update one of the config files that you had defined. All is fine and wonderful right up to the point where a Session variable was accessed. For some unknown reason, it was gone.

If this particular situation sounds familiar, there could very well be a good reason. It is similar to what happens if web.config gets updated on an active virtual directory. At least the symptoms are. What is actually happening is that the web application gets restarted. So it should be a surprise, should it.

Well, no. With one minor exception. In the particular case we were looking at, the config file was actually defined as an external file. So in web.config there was an entry similar to:

<customAppSettings configSource=”customAppSettings.config” />

So the actual updates were taking place outside of the web.config file. Since web.config isn’t updated, the application shouldn’t restart. Should it?

Well it turns out that the default behavior of the Config API is that changes to the external file cause an application restart just like web.config. And with the application restart comes the loss of Session information

There is a way to modify this default behavior. In the <section> tag where the config section is defined, the restartOnExternalChanges attribute gets set to false.

<section name="customAppSettings" type="ObjectSharp.Demo.CustomAppSettingsSection, ObjectSharp.Demo, Version=, Culture=neutral, PublicKeyToken=a140608022e61b4b" restartOnExternalChanges="false" />

All of a sudden updating the config file doesn’t cause an application restart and all of the little session variables remain fat and happy.


Missing vcvarsall.bat in VS.NET 2005 Command Prompt

I took a few moments to dig into a nagging problem this weekend.  Seems that whenever I launched the Visual Studio 2005 Command Prompt, I received an error message indicating that a file called vcvarsall.bat couldn’t be found.  A thorough search of the Visual Studio 8 directory found nothing of that name, although there was the old standby of vsvars32.bat. I took a further search through ladybug and I see that it had already been reported and marked as fixed for the release version. If you find this annoying, there is a workaround available.  The details can be found at http://lab.msdn.microsoft.com/productfeedback/ViewWorkaround.aspx?FeedbackID=FDBK24480#2, but it works out to be either install C++ or change the shortcut for the command prompt to run vsvars32.bat.

And so the migration begins...

I’ve been a fan of NUnit for quite a while now. There is nothing like it for increasing the likelihood of creating quality software in the face of shifting requirements. The philosophy involved with parallel development of unit tests and code is one of the reasons that I’m looking forward to Visual Studio Team Systems.  With NUnit-like functionality embedded in the IDE, the number of developers utilizing this approach should increase.  And, as it turns out, all of those NUnit tests that have already been created don’t have to be left behind. Thanks to Roy Osherove, I found out that a tool to convert NUnit tests to VSTS tests is being created by James Newkirk. I’ve already downloaded it and the playing begins.