Public musings, often on software development RSS 2.0
# Monday, January 23, 2006

Just a couple quick hits from this weekend's code camp.

Firstly, I'll have the materials from all three of my sessions posted on either Wed. or Thursday of this week.  I've got another presentation Tuesday night at the San Diego .NET User Group which I'm currently focusing on, but you are welcome to attend that meeting it's down in San Diego here's their website for more information: http://www.sandiegodotnet.com

Secondly after my session on Visual Studio 2005 and SQL Server 2005 I was asked a pair of questions.  The first question was "We are seeing tools put the T-SQL text of database statements into our source code.  Is this as good as using stored procedures?".  The answer to this question was easy.  Never use text based queries in your code as that leaves the possibility that you will be susceptible to SQL Injection.  There are several tools that will try to help ensure that this isn't possible by blocking special characters etc.  but the fact is the easiest solution which is also one of the most performance enhancing is to ALWAYS USE STORED PROCEDURES.

The second question they asked however caught me off-guard.  It was "We've seen that Microsoft tends to separate the Create, Update and Delete statements into separate stored procedures.  However, other tools have combined these with a simple flag to indicate which action should be taken.  Is there a specific reccomendation?".  Here my answer was that I couldn't think of anything specific and that although I always separated the items I couldn't think of a reason that mattered beyond style.  In this case the person asking was saying they liked to have a smaller number of stored procedures.... which has it's own disadvantage with multiple developers.   But anyway after the day was over and I was driving home the correct answer came to mind, which is that you should NOT COMBINE the CREATE, UPDATE, and DELETE statements in a SINGLE STORED PROCEDURE.

The reason is quite simple, security (again).  In this case it has to do with the fact that you of course are not using your 'SA' account for your website.  You should be using an account with limited permission (for a whole host of reasons).  So what's the big deal, well in most cases we design systems that don't allow a user to Delete an entry from one of our tables.  So if I have a stored procedure that creates my entries and I of course give anonymous or external customers access to that stored procedure then that's in the scope of what I expect a hacker might at somepoint compromise and I accept that risk.  However, if that stored procedure also contains the entry delete logic, then I have no way of limiting a user's permissions at the database level to prevent a hacker who might violate a small portion of my application's logic from doing significant damage to my application.  By separating out the Create, Update and Delete logic, I can create a security model which will prevent an anonymous hacker who get's unfettered access to my create logic from also being able to delete valid data from my database.

That's the short of what I consider to be a very good reason to not combine your Create, Update and Delete logic in a single stored procedure.

Monday, January 23, 2006 10:32:19 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
.NET | SQL Server | Technology
# Saturday, December 10, 2005

The slopes at Snow Summit and Bear Mountain have opened.  It's early season so it's only a couple runs are open and the services are a little limited, but crowds are also down.  We started skiing around 8:30/9 this morning went till a little after 11.  Took a lunch break till about 12 (this is the type of service that was a little limited...) Then went back out on the slopes till after 2:15 and took a break for about 30 minutes when I went back out for a couple more runs till almost 3:30.

For more infor on which runs are actually open up in Big Bear, I recommend this page which has two color coded maps (one for each resort) showing which runs are operating: http://www.snowsummit.com/photos.php

Saturday, December 10, 2005 8:06:13 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -

# Friday, December 02, 2005

OK, I was prepping for next week's VS2005 launch event in Anaheim when an odd thought struck me.  I was looking at this slide where Microsoft was defining what a 'Smart Client' application is (as opposed to a Thin Client or Fat Client application) and I realized that the term "Dumb Client" really had dropped from the technical vocabulary.

Now I'm sure that there are some high school age kids that will classify 'dumb client terminal' right up there with punch cards.  I did a search for "dumb client terminal" and got a grand total of like 13 hits on google and like 3 hits of MSN Search.  The fact is the days when people would buy a terminal with a modem and connect to a server that ran programs on the server and provided a text only interface are long gone and with them this term.  By the way the definition of 'dumb client' meant that the client litterally had zero application processing locally. Only the UI bits are sent across the connection and keystrokes are sent down to the server for processing (every keystroke roundtrips on a dumb client and isn't even echoed to the screen until processed by the server.)

Now we talk about the 'thin client' - a browser or Remote Client Window (think Citrix) as the distributed solution, but even with a thin client the client has some level of processing - for example browsers have Java Script which requires a client processor.  We don't think about solutions that relied on true 'dumb client' hardware.  For example in a dumb client scenario even a solution based on Java Script would need to execute the Java Script on the mainframe server round-tripping the IO to the client. 

Citrix is the closest thing to a dumb client, but of course to run it you need a PC or other fat client capable machine, because Citrix itself is a fat client application, you need a client with processing power to run it.  Thus even the remaining dumb client emulator is a fat client.  Apparently the old 90's argument that there would be a balance between the fat - smart - thin - dumb client applications has been safely decided...  dumb clients are gone clients applications will always be at least thin clients moving forward - and with scripting even the thin clients are getting thicker so you can even see the trend line - heck most phones have more processing power then the old dumb client terminals, and even those mainframes that still run dumb client applications do so using a fat client based emulator...

Friday, December 02, 2005 4:35:13 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
Musings | Technology
# Thursday, November 17, 2005

One of my least favorite errors when I first ran Static Code Analsysis was this security warning:

CA2209 : Microsoft.Usage : No valid permission requests were found for assembly 'IKRulz'. You should always specify the minimum security permissions using SecurityAction.RequestMinimum.

So what is the solution to this warning, and where in the heck do I set these permissions.  Well under .NET 2.0 you need an application manifiest (app.manifiest) file as part of your project settings.  The application manifest basically tells the CLR what type of security your application expects to need, so for example if your application requires full trust your app.manifest will look something like:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<
trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<
security>
<
applicationRequestMinimum>
<
defaultAssemblyRequest permissionSetReference="Custom" />
<
PermissionSet class="System.Security.PermissionSet" version="1" Unrestricted="true" ID="Custom" SameSite="site" />
</
applicationRequestMinimum>
</
security>
</
trustInfo>
</
asmv1:assembly>

Which is of course a totally simple thing to figure out right?  OK, so does this mean you need to start going to all your app files and adding what are best described as some somewhat obscure XML properties to define your apps security settings.  Well no not under Visual Studio 2005.  With VIsual Studio 2005 you can simply go to your project properties and there on the edit pane is a right hand panel for Security, as you can see below:

Now that you are on the security pane you can choose to enable your ClickOnce security settings.  This will generate your App.Manifest automatically.

But wait there's more.  As you'll probably see in every demo with Visual Studio 2005 it is possible to mark your assembly as having less then full rights.  The key to this is the "Calculate Permissions" button you see above.  This button compiles your code and using reflection determines what permission level your code actually needs.  In my case the code references local files system files, and therefore requires full trust.  However, the ClickOnce options allow you to determine that on the fly and have Visual Studio 2005 automatically determine whether your application will meet your deployment model.

Thursday, November 17, 2005 5:47:57 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
.NET | Team System | Technology
# Wednesday, November 16, 2005

So one of the new features I've found with Static Code Analysis in Visual Studio 2005 is that it allows you to suppress messages.  As I blogged earlier, the typical behavior is for the tool to add a line to your source file to suppress a warning that you find to be unnecessary.  So I was playing with the Namespace related rules which allow you to try and keep variables named appropriately and it flagged the namespace name I used.  I have an acronym as my Namespace and that meant it’s all capitals which of course the rule didn’t like.  So I decided to ignore the warning, only this time since the warning occurs across several files instead of adding a line to each file which referenced the namespace the Static Analysis tool created a new source file called GlobalSuppressions.cs and added the suppression line to that file.  Here are the contents of this new source file in my project:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1705:LongAcronymsShouldBePascalCased", Scope = "namespace", Target = "IKRulz")]

 

As you can see the only thing in the file is the declaration to create an exception for that rule, but in theory I could add other rules to this file if I found the same message in several locations in my code allowing me to limit the number of times I needed to exclude a particular message.  Of course I could also just avoid running certain rules, but that’s a different discussion.

Wednesday, November 16, 2005 9:34:24 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
.NET | Team System | Technology

With the loss of easy access to Flight Line we've resorted to our older route through Calavera.  So this morning at 6:30 we did about an hour on the basic loop through the trails of Calavera.  Eventually we'll look at tracking a time, but the thing with our Calavera route is that we tend to stop at the route's high point.  The view is spectacular, the picture below doesn't nearly do it justice... to put it in perspective about 10 degrees to the right of the power plant was a large white container ship that was visible from the point we call the office - but which just can't be seen in the low quality camera phone picture.... 

Wednesday, November 16, 2005 9:20:47 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
Cycling
# Tuesday, November 15, 2005

One of those things which you need to do every so often and it takes longer then it should to remember how... and even Google does a poor job on a quick search of returning the simple step you need.

After you type in the FTP://site/dir to your browser (and probably gotten a credentials required message) you need to go to the file menu.  On the File menu select "Login As..." and then enter the credentials for the FTP site you are trying to access.  It's simple just not something most of us need more then about once or twice a year.

Tuesday, November 15, 2005 3:04:50 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
Technology

I've been remiss on my bike updates and wanted to get a quick one in for a few pending items:

First off I'm proud that I managed to meet my mileage goal for the year.  The odometer on my bike turned past 5850 this morning meaning I have my 2000 miles for this year.  So my new goal between now and year end is to get past 6,000 miles so I can say that I've averaged 2000 miles a year since getting my road bike.


Secondly I wanted to record for posterity (my benefit) my times to work in the morning so I can have a long term record and appropriate expectations.  Riding down the coast my goal on reaching the office is to have an average speed of 17.5 mph.  My last 4 rides were:

  • 17.6 mph for a riding time of 28 minutes 20 seconds
  • 17.8 mph for a riding time of 28 minutes 12 seconds
  • 18.2 mph for a riding time of 27 minutes 22 seconds
  • 17.6 mph for a riding time of 28 minutes 22 seconds 

Note I've been measuring speed to the start of the office lot and then I don't pick up the time until after I park my bike so there is a little slop on the time side.


Next up I wanted to mention the loss of our typical entrance to the flightline area.  We've seen the construction crew dig like a 30 foot hole on our old path.  Fortunately the anonymous trail guy has been at work.  There is a new entrance that allows access to the trails we've been riding.  It's back by the skate park and is too steep to ride up and to be honest I'll be concerned about riding down it.... but it is there.

Anonymous trail guy has also put in a bridge for the crossing from Calavera to Flightline so transistioning between the two areas is much easier.  Anonymous trail guy does some amazing work if you ever get a chance to see that bridge on this crossing (or if I manage to remember to post a picture).

Tuesday, November 15, 2005 10:30:11 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
Cycling
# Sunday, November 13, 2005
Time to show I do sometimes surf and that I don't only think about biking and software. One of those 'quizes' which matches your personality to some category. This one was based on Tolkien's Middle Earth. I had one question on which I was undecided... it apparently makes a difference in my result on the one answer I get:
Hobbit
but if I go with my other option (both were pretty much equal in my mind - should great deeds be remembered in tale or by renaming a street or town were my two equal choices.
Dwarvish
To which race of Middle Earth do you belong?
Fact is the second of these is probably more me today just as Merry and Pippen would not have been as true to the typical Hobbit nature and a bit more Dwarven after their adventures.
Sunday, November 13, 2005 9:42:39 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
Musings
# Friday, November 11, 2005

When working with the Team System Static Code Analyzer there are times when the tool will throw out an issue that isn’t something you are going to resolve.  Of course when you first run the code analyzer it’s not uncommon to have a list of literally hundreds of potential issues.  As I’ve discussed in the past, the best solution when this list is long is to use the configuration settings to limit the areas of focus to things like performance and security and then move on to other areas.

 

However, as you are processing your potential issues, the fact is that some of those items won’t be issues.  It’s very possible that the tool might warn about code which in fact in the limited context where it is used is implemented correctly.  As such it’s important to be able to make those issues disappear from the overall list.  In fact let me provide some sample code:

 

    private void stackButton_Click(object sender, System.EventArgs e)

    {

      foreach (ToolStripItem item in this.stackStrip.Items)

      {

        if (item != sender && item is ToolStripButton)

        {

          ((ToolStripButton)item).Checked = false;

        }

      }

    }

 

So if you take the method above you’ll see that it is referencing an untyped collection of items, and by reviewing the ‘if’ statement we can tell that it is looking for one of multiple possible types in that collection and then casting and using objects of that type.  Pretty straightforward and in the context of what it does I don’t see a better way of handling what it’s doing (you are welcome to educate me in the comments section…)

 

When I run this code through static analysis what I get is the following performance related warning:

 

CA1800 : Microsoft.Performance : 'item', a local, is cast to type 'System.Windows.Forms.ToolStripButton' multiple times in method StackView.stackButton_Click(Object, EventArgs):Void. Cache the result of the 'as' operator or direct cast in order to eliminate the redundant castclass instruction.

 

However if you look at the code the fact the casting from a functional standpoint is done only one.  There’s no real redundancy of the casting instructions and no reason to cache the results.  So what should we do, well we should indicate in the code that this condition has been reviewed and isn’t something we want to be warned about.  Right clicking the error in the error list I select the “Suppress Message(s)” option from the context menu and the current warning is shown with a strike-through font.  On subsequent builds/checks the error is not displayed.

 

Which begs the question of how does Team System implement this rule exception?  The answer is that it adds an attribute to my source code.  This attribute is actually a method call which tells the code analysis engine to ignore one or more rules in the scope of the current method call.  Below is the instance of the SuppressMessage call attribute for this example message.

      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]

 

This call allows the code analysis to recognize which message has been suppressed in future runs, and because it’s part of the source code the suppression is checked into source safe and easily recognized by others looking at the code.  In addition to the SuppressMessage method there is a SuppressMessageAttribute method which has the following signature:
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]

 

This example of that call is for a different message generated by migrating code from the Beta versions of VS2005 to the release version… in this case I want more time to investigate the implications of making the change suggested by the message to ensure that I eventually do this I can add a task to my TFS project, but that’s a story for another post.

Friday, November 11, 2005 1:32:19 PM (Pacific Standard Time, UTC-08:00)  #    Comments [0] -
.NET | Team System | Technology
Archive
<January 2006>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
2930311234
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Bill Sheldon
Sign In
All Content © 2012, Bill Sheldon