Archive for the ‘Code and Development’ Category

Logging all SQL from nHibernate

April 16th, 2015

There are several ways to see what queries are used by Nhibernate.

If you are doing serious development I recommend Nhprof. It costs some but it is second to none regarding overview and ease of use. One bug caught and it is paid for. The GUI is a bit clicky but does a good job of providing good S/N ratio.

Sniff the traffic. I have not done this seriously but once wrote an ADO sniffer since there wasn’t any profiler for MsAccess.

There there is tracing the RDB. Possibly gratis or even free, depending on database (I haven’t checked them all, only Microsoft’s one). In my experience it is too noisy to have running during the whole development cycle like one can do with Nhprof.

Then one can use Nhibernate itself to log. Check Nhibernate succinctly, chapter 12, for how to setup Nhibernate with Log4net. If you want to log through another framework the same author wrote an article.

Wrap the logging framework

April 15th, 2015

If you haven’t decided whether to use Log4Net, EnterpriseLibrary, nLog, home baked or any of the other logging frameworks – wrap it or abstract it.

Common.Logging is an “ordinary compiled lib”. It is strongly named with its pros and cons.

LibLog on the other hand is just a file (like Dapper). When developing a lib for public use this might be good to keep fewer dependencies.
The author of LibLog mentioned some pros for LibLog (vs Common.Logging) here. It uses dynamic and Tuple so it is Dotnet4+.

Simple Logging Façade is a compile lib, like Common.Logging.

How to open and edit an erx / ER diagram file in Toad

October 21st, 2014

Creating an ER diagram in Toad is simple. Opening is not. Searching the intertoobs gives the result, mostly, to use Toad data modeler. My Toad data modeler version 5.1.1.12 simply refuses to let me add new tables to a diagram.

So here is my solution.
First ditch Toad data modeler.

Create the ER diagram in Toad->menu->Database->Report->ErDiagram.
Manipulate.
Save.

ER diagram menu in Toad.

Open an existing ER diagram through Toad->menu->Database->Report->ErDiagram as above.
But instead of editing look on the ugly toolbar for Open file.
Now one can edit the ER diagram.

Open file button in numerous tool bars in Toad.

How to set up IIS 7.5 to use an Apppool user to connect to Sqlserver

October 6th, 2014

Honor those who should.

Setting up a new Web site and then connecting it to Sqlserver is a breeze if one uses the development web server.
But if one wants to use the real McCoy, i.e. IIS, there is more work.

iis apppool: http://www.selfelected.com/iis-7-iisapppool-lightly-explained/

 

Why use the real IIS when it is so cumbersome?  Because it looks more like the real production environment.

How do I debug?  Like this:

Start Visual studio i in administrator mode. (if one doesn’t, VS is helpful with this)
Then ctrl-alt-p (menu:debug:attach to process) and choose the w3wp.exe process, with the right user name. Attach. Debug.

Copying a virtual machine in hyper-V

October 6th, 2014

Here is some short info. Hyper-Vmanager 2008 I believe.
I also believe one must not have snapshots. The programming here really sucks – having a snapshot stops you from handing the VM.

Stop the source VM machine.

Export source machine. One has to select a folder “one step up” since Server manager will create a folder with the name of the source VM.
Depending on VM size this might take a while and there is no visual clue about how far the copying has come.

If needed: Change the name of the folder of the target files just created. Don’t change anything within the folder structure, just the top folder. This is done in Explorer.
(I really should create a visual example here on which folder goes where. Not hard but easy to miss a step.)

Back to Server manager and Import virtual machine. Set the radio button to Copy the virtual machine. This takes care of syspreping. Don’t bother about duplicate all files; It should be used when many machines are created, not just one extra as in this example.

Importing has a visual clue. It is in its own window, without task bar presence, so if it disappears you might have to minify everything to make it visible.

Now you have to machines with identical names. Not good.
Select and then choose Settings and typically IDEController0 for the one or other to find out which resides in your newly created folder. This is our target VM.
Change the name of this machine.

Now find the folder for the target VM again. Locate the vhd file. Make a copy of it with the right name.

Back to Server manager. Go for Settings and (typically) IdeController0->Virtual hard disk->Browse. Locate the copy you just made. Press ok. Wait.

Now the machine should be startable. Try it.

If ok. Delete the old vhd file.

Xpath axes explained

September 15th, 2014

The original article at explains it best.

If the original article goes missing I have copied it here as a web archive.

All kudos goes to the original author, not me.

The following picture from Crane Softwrights demonstrates the axes graphically.

 

Dotnet, Sysinternals DebugView, Debug.WriteLine and IIS

September 6th, 2014

I finally managed to write through Debug.WriteLine to Sysinternals DebugView through reading this article. Kudos to the author.

If the original article disappears; here is the recipe in short:

Start Sysinternals Debugview as administrator. Make sure Capture global win32 is checked.
Make sure Visual studio is not attached as debugger because when you run the VS debugger it hogs all information. (In VS you can find the output in the Output window with Show output from Debug.)

Besides Debug.WriteLine also play around with Trace.WriteLine and Console.WriteLine.

Unit tests and comparing long strings or objects

June 16th, 2014

I have tested and really liked ApprovalTests with more info in the blog by Llewellyn Falco.

When the unit test fails, and only if it fails, a comparer of choice pops up (think Winmerge or similar).

Say you have a long string where, somewhere, the testing framework reports a diff; you have to sift through the whole 1000 characters and compare by eye. If the discrepancy is a space/tab or apostrof/accent you might have a very hard time to spot the diff.
Or say you have an object with 10 or so properties. The unit testing framework reports a diff and you have to iterate through the properties and maybe sub properties for two objects. Tedious and not fun even the first time. The third of 10th time you really should be looking for a better solution.

I started writing my own but dropped that project in a second for AprovalTests.

Another, not as polished, solution is from SHaack. It is an extension to a unit test framework. You have to implement your own if you have another unit testing framework of choice.

Why I don’t recommend my customers to rely on Visual studio for development.

June 5th, 2014

Abstract

The only way to edit architecture and modelling with Visual studio is to buy the very expensive Ultimate edition. This means that it will be not everyone can be involved in the process of evolving the solution.

 TL;DR

Development requires Architecting an Architecture in some way or another. This architecture is not written in stone but changes as time or business changes; we call it requirements change.

In the old days, like 20 years ago, I learned that there is an architecture phase and then a development phase. This is not considered best practice any more. Also not best practice is to have silos with Architectures and Testers and Coders and Database managers.

This is where Microsoft and Visual studio fails. Not technically but license wise.

Look at this part of a comparison chart for different Visual studio versions. It clearly explains that Architects must have the Ultimate edition and that no one but Architects are allowed to change any Architect document. (the Ultimate edition is way more expensive than the others)

Visual studio architecture blunder

Visual studio comparison fail where it shows that only Ultimate can edit architecture stuff. Original from Wikipedia.

ReAttach is a Visual studio plugin to reattach the debugger

May 9th, 2014

I have earlier, here and here, written about how to write a macro to attach the debugger to a running process as it is often faster than starting the process anew.

Lately the Visual studio plugin ReAttach has come on my radar and I have tried it with success. It remembers the last attaches you did and keeps them in a menu. Fewer key strokes and fast attaching is the result.