Thursday, December 11, 2008

Silverlight – Under the covers

About 6 months ago, I “blogged” about the book that I had chosen as my summer reading - Essential WPF. Due to some personal problems, however, I was unable to complete my task before the summer end. But “I'm catching up” and I'm half the way with eating Chris Andersons’ words. I must say that the book hasn't convinced me yet, but I'll leave that thought on hold until I'm finished reading it. Nevertheless, every technical book has that little bag of knowledge that can surprise you.

Essential WPF actually answered my biggest question around Silverlight: How on earth does it work? What runs where? Under what security permissions?

Well, WPF hosts applications by implementing an ActiveX DocObject (OLE DocObject). This means that every application that supports hosting DocObjects can actually host WPF applications. To know how to interpret the XBAP extension, when the .NET Framework is installed, a mime handler is registered for the XBAP extension, which loads up WPF. "The real deal" comes next. WPF runs all browser-hosted applications out of process, using a host application called PresentationHost. This isn't what I expected and actually takes me to the answer to one of the questions made above: If it's running "out of the browsers' scope", under what security permissions is it running? The answer is simple: Quoting Chris Anderson, "on Windows XP, PresentationHost.exe is launched with modified NT permissions. The admin token of whatever permission “iexplore.exe” is running is used to set the security permissions. On Windows Vista, the Limited User Access feature provides this same type of security model.”

This is quite intriguing and has brought a few more questions to my head, especially concerning on what’s going on “under the covers”. But let me solve them by myself first and I will post back later.

The Silverlight world is new to me, I wonder if it will amaze me as much as the WF did for the last year.

Saturday, December 6, 2008

Export MIME Types from IIS

I usually don’t share “my homework” or “personal developments”, but this might actually be useful at work for some of you. It’s quite simple: the idea is to export all the MIME Types registered in IIS. Furthermore, you can generate an HTML page (with style sheet) from the exported MIME Types. Here's how:

      1 – MIMETypesVBScript.vbs: the VBScript that will get the MIME Types from IIS. Note that if you are using the script on a remote server (through remote desktop, VPN, whatever), you might need special permissions to execute it.
      2 – MIMETypes.XSL: The file that will apply the style. Feel free to develop your own.

Just save the files from Github and run the VBScript (cscript MIMETypesVBScript.vbs). Finally, use the XSL to transform the XML generated. That simple.

Thursday, December 4, 2008

Scary – SyBase

In my opinion, SQL Server is the most complete DBMS. For the past couple of years, I've worked with it from the basic T-SQL to the most administrative clustering, security and so on.
But despite my preferences (Microsoft), it's always good to keep your mind open to other solutions around you. For instance, I also appreciate MySQL, which is a great solution for small business (free).

The last month, however, I've worked with SyBase. SyBase is known by many people as being the "cousin" of SQL Server for historical reasons. Of course, the syntax isn't much different from SQL Server, but the tiniest difference can have a big impact. Take the following example of a stored procedure in SQL Server:

Stored Procedure

You can call this procedure passing no parameters or one:

And that's it. If you pass more than one parameter, the SQL Server Management Studio will yield an error message:

Msg 8144, Level 16, State 2, Procedure DefaultParameter, Line 0
Procedure or function DefaultParameter has too many arguments specified.

Now, the same procedure can be written for SyBase... exactly the same! However, in SyBase, you can call the procedure with "n" arguments:

The DBMS will take just the number of arguments that the procedure wants, ignoring the rest of them. This is quite odd!

The problem I had at work was that someone created a procedure with 2 parameters, both varchar. Then, all the other stored procedures were written to call this procedure with two varchar parameters. Somewhere in time, the second parameter was no longer required and was removed from the procedure definition. Of course, the code that called this procedure kept running because SyBase allows the procedure to request just one parameter and the caller to pass two parameters.

My task was to add a new output parameter to the procedure. It now had 2 parameters again, but the one I added was of type integer. Can you imagine what happened to all the calls to the procedure? Bum! They where passing two varchar variables and now the procedure is expecting one varchar and one integer. Scary...

I haven't searched for an explanation for this behaviour (nor I'm going to) because I'm sure it won’t convince me. So, that's one point less to the SQL Server cousin.