Archive for the ‘tip’ Category

January 9th, 2010

>

This is my visual setup of Visual Studio.

Notice how the real estate is used for tools I use and not for buttons that just happens to be there by default.

shift-alt-return maximises the window so not even the caption bar is visible.  I know which program I am working in so I don’t need to waste the whole top for this.

I have removed all toolbars.  The buttons I need I have put to the right of the menu.

There are also two macros in the menu bar, one for connecting the bugger to nunit and ditto to IIS.

I have set all toolbars to auto hide.  When I debug, the call stack and autos (unfortunately hard to find among the menus with C# projects – open a VBNet project and see what it looks like), toolbox are visible.

I have also moved all toolbars to the right.  When one is working heavily with the forms designer it is good to have the Toolbox toolbar constantly open on the left but only then, and for the 2% of the project I handle the forms I can move it there manually.  The rest of the time I hack code and need nothing but code and debug tools.

I know shortcuts to almost all toolbars.  Those I don’t know I don’t use that often anyway.  I don’t know why some banjo player at Microsoft decided that underlines and shortcut tips should be invisible as default.  Fix it through Tools->Customize.

This way I use all of the precious display area for stuff I have use of.

>String.IsNullOrEmpty

December 14th, 2009

>

Instead of

    if( null == myString || string.Empty == myString ){…

one can use

    if( string.IsNullOrEmpty( myString ) ){…

There is nothing magic about it, just a more readable, and hence less error prone, syntax.

It would be nice of someone could solve the

    if( null == myCustomer.Address || null == myCustomer.Address.City || null == myCustomer.Address.City.Name ){…

-problem.

In Dotnet4 there will be a method similar to IsNullOrEmpty which also checks for whitespace.  It should come in handy.

categories: tip | 2 comments »

Database versioning

December 8th, 2009

Since I have abandoned Visual studio database edition because of it not being able to handle tables with data I have returned to my old, proven, way; checking in/committing the update scripts and storing a database version number in a Setting table.

In Microsoft SQL Server Management Studio (or whatever it was called earlier) there is a setting to always create update scripts whenever a change is saved.

Then whenever a change is done, store the update scripts with consecutive version numbers.  These versions are not the same as the release versions but one version number per commit.

013_01_S_Customer_Added the CompanyColour field.sql
013_02_D_Customer_Set the CompanyColour to red except blue for McCarthysen.sql
013_03_S_Customer_Set CompanyColour to notnull and no default value.sql
013_99_D_Setting_Updated database version.sq
l

013 is the version number.  Next commit is 014 etc.
01, 02, 03 are consecutive numbers.
99 is the final number for this commit.  It always contains an update in the Setting (or whatever you call it) table and sets the version number record to 13.
S and D are Schema and Data respectively.  I have learned that it is good to see this already in the script’s filename.
Customer and Setting are the names of the main manipulated tables.
The rest is free text that explains what the script does.

It is now very easy to see how far a database is in the development flow.  Select the the row from the Setting table and notice its number.  Then run all scripts with higher version numbers in the right order.  The scripts are easy to order by their names directly in the version manager or in the file explorer after a checkout/getlatest.

This technique works well with several developers.  Store the scripts locally until they you are ready to commit the code.  Update the version number if someone already used the version number.  Commit.

A tool like SQL compare does approximately the same job.  If you have only a few updates with a few databases it is way faster to just create a diff-script and run it.  Contrary to VSDatabase edition SQLcompare handles tables with data.  It costs money but 1) there is a trial version and 2) it is way cheaper than hacking the code yourself.
There are other tools as well and I have used one but I cannot remember the name of it.  It was not as easy to use as SQLcompare if I recall correctly.

If you have to handle several versions while developing the procedure I have described here is good since it is so easy to check the version of the database.

(I just stumbled upon a situation where saving a view and only updating the output fields from lower to upper case (customername -> CustomerName) did not result in a script file.  In this case there was no problem in scripting a drop/create script through the Object explorer tool box though.)

categories: database, tip | one comment »

>Edit project file in VSNet

November 28th, 2009

>

There are mainly 3 ways to get to your Vsnet project file to edit it.  (disclaimer: I am running Vsnet2008 and haven’t tried earlier nor later versions)

1) Open windows explorer and navigate to your project folder.  Open the project file (.csproj/.vbproj/…) in your favourite xml editor.

2) Install a tool that gives you an “Open folder in windows explorer” context menu item in the Solution explorer.  If I recall correctly the tool I am referring to is Microsoft’s Team foundation server power tools.  Please correct me if I am wrong.

3) Unload the project.  Use the context menu in Solution explorer to edit the project file.  Load the project again.

categories: tip | no comments »

>Traverse Corporate Firewalls

November 4th, 2009

>

Sometimes a solution is so secure it becomes insecure.  The primary example of this is requirements for passwords that are so complex that people write them on a note and stick them under their keyboard.

I have several times been locked into a corporate network where the possibility to cooperate with the outside has made my work more complex and expensive.
Limited email storage and chat protocols that don’t make it through the router are things that might hinder my work all the way to effectively stopping it.  A limit of 100 megs of email storage makes it impossible to send large emails without risking filling the mail box of a colleague.  Without chat my communication with competence peers is severed.

A slow internet connection makes every search take longer time or give less thorough result.

Then there are hinderances like forbidden FTP, an email washer that stops binaries and source code, or the stopping of youtube in the firewall.

I live in a world, a community, and we communicate.  A big part of my work is to gather information and spread it to interested parties.  Too many times the rules of a corporation network limits this.  Hence workarounds that don’t always play well with security but makes my customer happy.  And that is what it is all about, helping your Customer.

Wired has an article http://howto.wired.com/wiki/Traverse_Corporate_Firewalls that explains some workarounds from the dead simple to way more complex.

categories: tip | no comments »

>Slow sqlserver express

June 5th, 2009

>

I got informed of something somewhat strange the other day.  Microsoft SQLServer Express runs (connects) faster if you have a query window to the database already.

Like this:

Have a freshly booted machine with only Visual studio running and your web application of choice.  The time for a refresh of you web page might take 5 seconds.

Now start Management Studio and open a query window.  Let it stay open.
Refresh your page and you are down to a second.

The figures might of course change but they are what I have on a dual core 2GHz 4MB machine for a project of size X and database of size Y.

—-

I haven’t checked if the same thing happens with another script editor like for instance AnySQLMaestro but guess it does.  I guess it has to do with connections – as long as there is a connection to SQLExpress, it doesn’t close.  If so, it corresponds with the product’s raison d’être, a database for applications.

—-

I have noticed a correspondence between debug-start-delay and quality of code.  I say that every second wasted waiting on debug start makes the developer unwilling to test more thoroughly and leads to more bugs in the product.

—-

Another trick to make web debug start faster here.

categories: database, tip | no comments »

Timer and GUI

April 17th, 2009

One cannot use the System.Timers.Timer to update the GUI, instead one gets a cross-thread exception. The GUI can’t be updated from another thread.

A nice trick to solve this is to use a method that is sensitive for if the call comes from another thread than the GUI is running on.

   private delegate void SetTextDelegate(Label label, string text);

   private void SetText(Label label, string text)
   {
       if (this.InvokeRequired)
       {
           IAsyncResult res = BeginInvoke(new SetTextDelegate(SetText), label, text);
           EndInvoke(res);
       }
       label.Text = text;
   }

Honor those who should.

categories: code, tip | no comments »