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.
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.sql
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.)
December 1st, 2009
If one wants to run a virtual machine on Windows 7 Windows Virtual PC is the official way to go.
It requires hardware supported virtualization though, which means not everyone’s machine can do it. On my HP 8510w it meant a cold reboot – just restarting and changing the BIOS was not enough.
The older VirtualPC2007 doesn’t need any hardware virtualization stuff and a small text about how to install it is found here: http://blogs.msdn.com/virtual_pc_guy/archive/2009/08/19/running-virtual-pc-2007-on-windows-7.aspx
It looks like Microsoft wants everyone who installs Windows Virtual PC to also install Windows XP Mode by some reason unknown to me. I am a developer and I am hesistant to installing apps that might tweek the OS.
The whole page at http://www.microsoft.com/windows/virtual-pc/download.aspx pushes you into installing Windows XP Mode but if one selects a system at step 3 two buttons pop up and one of them says “Windows Virtual PC”.
Download and install. But instead of the usual application GUI one gets a view of a folder under C:\Users\username\Virtual Machines prepared for virtual machines. This might be good for people who backup what is under their personal account but as a developer I don’t want to tie my data to an account and instead prefer something like C:\DATA\VMACHINE\.
Come to think of it – is it good for anyone?
It also took me a while to find out how to create a new virtual machine. Instead of having an app with a button or menu as is de facto standard someone has decided to hide the button in the toolbar or extra menu system ( I have never figured that out. )
Don’t bother to cut and paste the .vmcx file to some other place. It will be copied but not removed so you end up with the original .vmcx file in the original place and a not functioning copy of it in your target directory.
The .vmc file can be run though.
Mount an ISO with your preferred OS on the virtual D: drive. The virtual machines chews through your NICs and DHCP. I had my WLAN card turned of in the host OS, but the virtual machine seemed to first look for my WLAN card and then my regular one.
The rest looks just like ususal.
November 29th, 2009
When I have written Vbnet and checked for Nothing I have chosen between
If Not( o Is Nothing ) Then
…
and
If False = o Is Nothing Then
…
and
If o Is Nothing Then
‘ NOP.
Else
…
all ugly and/or hard to read but in their own way.
Some days ago I stumbled upon IsNot and since then my code looks nicer like so:
If o IsNot Nothing Then
…
I have been writing Vbnet for years without finding IsNot so I thought there are more out there with the same problem.
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.
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.
October 18th, 2009
Try to attach a database with Management Studio when using Windows 7 and SQLServer 2008 developer edition and one might get an error message similar to the title of the article.
Whether this is a bug or not is beyond my knowledge but the solution/workaround is to connect as SA and not as windows authentication.
October 18th, 2009
If one uses trusted connection to a sqlserver database under Windows 7 and II7 one might get the error message “Login failed for user ‘IIS APPPOOL\DefaultAppPool’.” when trying to run a web application. There are several articles for this but all points to a different GUI than mine (earlier versions of Windows7/IIS7?).
Update: as I lightly noted, to give the apppool SystemLocal rights is Not the right way to go.
Set up the application pool in IIS
Fire up Internet Information Services Manager. (windowbutton-iis-return)
Find the Application Pools item in the Connections toolbar. One can reuse the default application pool or create a new one. Go for the latter since it is slightly more complicated and hence more fun.
or in Win8:
(I don’t grok what Managed pipleline mode does.)
Select your newly created application pool and the advanced settings. Change the Process model to LocalSystem.
(I had planned to create a “better” account with the proper limited rights but ran out of time. Someone else…?)
Update: Don’t change to LocalSystem, instead add the user to allowed SQLServer logins as noted in the bottom here. I suggest “IIS AppPool\MySite” for now.
The recommended Microsoft solution is to create a separate account. However, if your solution is small, you can instead add the ‘IIS APPPOOL\DefaultAppPool’ user as a database user in your SQL instance, then providing the proper ‘User Mappings’ to the databases you need the DefaultAppPool user to access. You may not necessarily be able to search for this user, but you can still enter it in the ‘Login name’ field in the “Login – New” window as “IIS APPPOOL\DefaultAppPool” (without the quotes).
Follow this link as a reference and pay attention to the last post: http://social.msdn.micro…-4a71-a448-3e3eef9ee404/
Application pool settings
Getting to advanced settings.
Application pool advanced settings
Site settings
Now change your web application to use this application pool. This could be made simpler by moving the menu for this to the same place as the other menus. To make the story short – select your site and look to the right of the IIS manager.
Site advanced settings.
Site advanced setting IIS7.
Application pool.
Application pool in IIS7.
Set up Sqlserver
Honour those who should.
To add a new user to SQLServer go to your database->security and add user connected to IIS APPPOOL\DefaultAppPool. This way the user can log in to the database.
Sqlserver -> new login.
New login to database. Don’t forget to change default database to appropriate.
Then go to the SQLServer->security and add this user to be allowed to login to the server through the user and properties.
The users of a database.
That is all there is to it.
October 5th, 2009
>
Microsoft has for a long time had a very simple application for mounting ISO images to look like a CD-ROM. The application is called Microsoft Virtual CD-ROM Control Panel.
It is hard to locate though. The very link is here:
http://download.microsoft.com/download/7/b/6/7b6abd84-7841-4978-96f5-bd58df02efa2/winxpvirtualcdcontrolpanel_21.exe
and can for instance be found through here.
It works for 2000?, XP, Vista, 2003, 2008? but not Windows7.
October 5th, 2009
>
Installing Visual Studio 2008 is a breeze. Installing it to work with TFS is not so. It is not even enough to install the Visual Studio 2008 TFS update but one has to install Visual Studio 2008 SP1 as well. In this written order.
And here is where I got this information.