Browsing:

Month: July 2011

Db4o with Castle Windsor and ASP.NET MVC 3.

This is how you can use Castle Windsor inversion of control container with Db4o. In this example I use the Db4o Server rather than the embedded version.
That’s because I want to be able to make multiple connections to Db4o in an ASP.NET MVC 3 application. So here is how it is. (It is rather short because it is so easy, or perhaps I’m missing things? Let me hear it if I do!).

First, open the package manager console and add the following packages:

[code]
Install-Package db4o-cs-devel
Install-Package Castle.Windsor
[/code]

And in the TestProject:

[code]
Install-Package Nunit
[/code]

To get started with ASP.NET MVC 3 and Castle Windsor, just follow this excellent documentation. Don’t forget however to put this line in your web.config, in the System.Web section:

[code]
<httpModules>
<add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" />
</httpModules>
[/code]

I decided to use a generic repository. Since I use a Db4o Server (see the docs), connecting to that Windows Service returns a Db4o session (IObjectContainer). So I can use that session in the Repository.
This is also very testable.
But first let’s hook it up in Windsor:


Isn’t that simple?
We’ll use the IObjectContainer like this in the repository:

And finally, the Controller looks like this:

Please check out the source code here.

The Buttonfactory Db4o Windows Service

I know, this has been done before, here and here, and these people did it much better than I did, but I thought it would be nice to write a Db4o Windows service myself. Just as an exercise. I also wrote a WPF frontend so you can control the service easily:

You can download The ButtonFactory Db4o Windows Service and Configuration Tool here: Db4o.Service.Installer.Setup. Mind you, it is all very beta and I really need to test concurrency.

Here is the complete source code.


Tooltip of the Month: How to detach and attach a sql database

Since the new Denali database really rocks my socks.dll,  it’s time to move the old databases from SQL 2008 R2 to Denali. It’s time for a quick and dirty database migration!

If you want to skip all the effort from backing up a database, copy it to another disc and restore it as a new database, then try this!

There are two ways to achieve a succesfull detach and attach, with management studio and with stored procedures, I will give both examples:
First make sure the database you are moving doesn’t have any related services running from the application or has active sessions to the database. ( sp_who Active)

from script:

We will be moving a database called kvdn, we need execute two relative simple queries. First one containing database name and whether we update the statistics. Update statistics will update and index columns and can increase the speed of your queries.

sp_detach_db [ @dbname = ] 'dbname'
[ , [ @skipchecks = ] 'skipchecks' ]

If ‘skipchecks’ is true, UPDATE STATISTICS will be skipped, to update the existing optimization statistics, change skipchecks to ‘false’.

EXEC sp_detach_db 'kvdn', 'true'

now we are going to attach in the new database environment
we need to provide database name and also filelocation for the mdf en ldf files

sp_attach_db [ @dbname = ] 'dbname',
[ @filename1 = ] 'filename_n' [ ,...16 ]

Open up the denali server and run this query to attach the kvdn database

EXEC sp_attach_db @dbname = 'kvdn',
@filename1 = 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\kvdn.mdf',
@filename2 = 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\kvdn_1.ldf'

We just succesfully moved the database.

and now for the gui way:

right click the database you want to detach and choose detach…

By default, the detach operation keeps your current optimization statistics, to update the existing optimization statistics, click the Update Statistics check box.

Now find the location if your database files, by default this will be “C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA”

move the files over to the new file location and open up the management studio where you want to have the database running.

right click database and select Attach…

Now insert the location of the database files

and that’s it, your database is up and running.

retrieving the database users:

I have seen examples where the users aren’t automatically moved along or stoped working with the attached database,  the easiest way is to just remove them, in case they did move and didn’t work and recreate them.

or re link them with the sp_change_users_login stored procedure:
EXEC sp_change_users_login 'Update_One', 'User', 'User'


Analyzing a server 2008 R2 dwp crash dump file

Yesterday the four node file cluster resource crashed and blue screened and was moved to another node. I wanted to analyze the crash dump file (C:\Windows\Minidump\070711-36473-01.dmp) so I copied it to my W7 workstation and tried to open it but Visual Studio could not help me out here.

Reading a crash dump file is far from intuitive and I spent a great deal of the morning learning about debugging. So here is what I did to read the dump file.

First, you need to install the debugging tools from here. Choose the version that corresponds to your architecture. This install will take a long time depending on your network speed. Important is that you include the WinDbg.exe because that is the tool we will be using.

Next, you need to download the symbol files. Note that you can also use the symbol server from Microsoft but it is faster to have a copy of the symbol files on your hard drive. Download them here. Just download them all. And this will also take a long time because the Symbol files are huge.

Next! Open C:\Program Files\Debugging Tools for Windows (x86)\WinDb.exe.
Choose File -> Open -> Symbol File Path

Type: SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols like this:

Now press CTRL+D to open the DWP file! Very exciting.

Now, if you enter !analyze -v like this:

And you’ll get more information about the crash. In my case:

[code]
8: kd> !analyze -v
*******************************************************************************
* *
* Bugcheck Analysis *
* *
*******************************************************************************

USER_MODE_HEALTH_MONITOR (9e)
One or more critical user mode components failed to satisfy a health check.
Hardware mechanisms such as watchdog timers can detect that basic kernel
services are not executing. However, resource starvation issues, including
memory leaks, lock contention, and scheduling priority misconfiguration,
may block critical user mode components without blocking DPCs or
draining the nonpaged pool.
Kernel components can extend watchdog timer functionality to user mode
by periodically monitoring critical applications. This bugcheck indicates
that a user mode health check failed in a manner such that graceful
shutdown is unlikely to succeed. It restores critical services by
rebooting and/or allowing application failover to other servers.
Arguments:
Arg1: fffffa8038f3ab30, Process that failed to satisfy a health check within the
configured timeout
Arg2: 00000000000004b0, Health monitoring timeout (seconds)
Arg3: 0000000000000000
Arg4: 0000000000000000

Debugging Details:
——————

PROCESS_OBJECT: fffffa8038f3ab30

CUSTOMER_CRASH_COUNT: 1

DEFAULT_BUCKET_ID: DRIVER_FAULT_SERVER_MINIDUMP

BUGCHECK_STR: 0x9E

PROCESS_NAME: System

CURRENT_IRQL: 2

LAST_CONTROL_TRANSFER: from fffff880030b76a5 to fffff80001a98d00

STACK_TEXT:
fffff880`0253d518 fffff880`030b76a5 : 00000000`0000009e fffffa80`38f3ab30 00000000`000004b0 00000000`00000000 : nt!KeBugCheckEx
fffff880`0253d520 fffff800`01aa4652 : fffff880`0253d600 00000000`00000000 00000000`40800088 00000000`00000001 : netft!NetftWatchdogTimerDpc+0xb9
fffff880`0253d570 fffff800`01aa44f6 : fffff880`030c4100 00000000`03023940 00000000`00000000 00000000`00000000 : nt!KiProcessTimerDpcTable+0x66
fffff880`0253d5e0 fffff800`01aa43de : 00000729`6e09a2ce fffff880`0253dc58 00000000`03023940 fffff880`02517d88 : nt!KiProcessExpiredTimerList+0xc6
fffff880`0253dc30 fffff800`01aa41c7 : 000001c5`99d9f3c1 000001c5`03023940 000001c5`99d9f3fd 00000000`00000040 : nt!KiTimerExpiration+0x1be
fffff880`0253dcd0 fffff800`01a90a2a : fffff880`02515180 fffff880`025202c0 00000000`00000000 fffff880`01368420 : nt!KiRetireDpcList+0x277
fffff880`0253dd80 00000000`00000000 : fffff880`0253e000 fffff880`02538000 fffff880`0253dd40 00000000`00000000 : nt!KiIdleLoop+0x5a

STACK_COMMAND: kb

FOLLOWUP_IP:
netft!NetftWatchdogTimerDpc+b9
fffff880`030b76a5 cc int 3

SYMBOL_STACK_INDEX: 1

SYMBOL_NAME: netft!NetftWatchdogTimerDpc+b9

FOLLOWUP_NAME: MachineOwner

MODULE_NAME: netft

IMAGE_NAME: netft.sys

DEBUG_FLR_IMAGE_TIMESTAMP: 4a5bc48a

FAILURE_BUCKET_ID: X64_0x9E_netft!NetftWatchdogTimerDpc+b9

BUCKET_ID: X64_0x9E_netft!NetftWatchdogTimerDpc+b9

Followup: MachineOwner
———
[/code]

Explanation: USER_MODE_HEALTH_MONITOR (9e) is the bug check code I need to investigate. For a complete list of bugcheck codes look here:
http://msdn.microsoft.com/en-us/library/ff542347%28v=VS.85%29.aspx

And now all that is left for me to say is: ‘happy debugging’.

Oh here are some helpful links:
http://blogs.technet.com/b/askcore/archive/2009/06/12/why-is-my-2008-failover-clustering-node-blue-screening-with-a-stop-0x0000009e.aspx

http://blogs.msdn.com/b/ntdebugging/archive/tags/hangs/