Tuesday, December 02, 2008

Database auditing trigger.

I run in an interesting problem lately. One of my application needs some auditing abilities, it needs to write the change to the change history table if a particular field is updated.

I google around, and found some information on MSDN, There is a T-sql statement called UPDATE, and allows you check whether it's a field is updated or not.

image

So, I think if write some T-sql statement

If Update( field) 
BEGIN
//write to the another audit table.
END




However, I was confused that the audit table keeps get new entries even I didn't change any data. Yes, that's trick, be aware the difference between "update" and "change", the If Update(filed) will returns true even you don't modify any data. If you want to log to the another table only when the data changes, then you need compare the deleted field value with the inserted field value. After all, the update statement is a delete statement followed by the insert statement.



So, you need so something like.



INSERT INTO AuditTable ( Field )
SELECT Deleted.Field
FROM Inserted
INNER JOIN Deleted
ON Inserted.Id=Deleted.Id
WHERE Inserted.FieldValue<>Deleted.FieldValue

Monday, September 01, 2008

Step into .Net source code.

I know it is one of the new features introduced in vs2008, but I didn’t test drive it until lately. Here is steps to set it up. My screenshot is  based on visual studio2008 service pack1, so it may be different with initial installation of visual studio 2008.

  • step 1: Go to Tools –>Options from visual studio, uncheck “Enable Just My Code”, which is set by default, and check “Enable .Net Framework source stepping”.

DebuggingSettings 

  • step2 :download symbols. I suggest that you click “load symbols from Microsoft symbol servers”, and this will download all the symbol files from microsoft symbol servers at once and cache them locally , so you can avoid keeping fetching the symbol server by uncheck “Search the above locations only when symbols are loaded manually”.

loadSymbols 

  • step3: when you hit the breakpoint, you can choose whether you want to step into the source code. Look at the following , you have two choices, when you choose step into specific, you can step into the set_Text function, when you choose step over properties and operators, you can step over it.

stepintoNetCode

 

References:

Releasing the Source Code for the .NET Framework Libraries

Configuring Visual Studio to Debug .NET Framework Source Code

Monday, August 25, 2008

Ignore a region in ReSharper

I posted this question in ReSharper forum:

I am sure I am not the only one who has this question.

When visual studio create some file when I go through wizard, for example, if I create a linq file (*.dbml) , it will create a *.designer.cs. Resharper will generate a lot of warnings for this file. (Total 342 warnings for a single file), Is there any way for me to disable those warnings for the whole file.

Or , is there any option that I want to disable checking for files with *.designer.cs, thank you very much.

Here is the answer I got :

I don't know if you can exclude a complete file or wildcard of files although I seem to remember this has been discussed sometime before. In the short term you could try this if you don't know about it already:

Wrap the code you want to exclude from analysis in a region, say, MyRegion. In RS' options look in the Code Inspection section and select the Settings item. In the Settings you'll see "Generated code regions:", Click the Add button and add your region name MyRegion as a new item. When you look in the code window you should now see that RS will ignore the contents of the region. I think the name you add is case sensitive. Does that help?

Friday, August 22, 2008

The blogs about windows debugging…

If broken it is, fix it you should

Microsoft Advanced Windows Debugging and Troubleshooting

Crash Dump Analysis

The first blog is the one of the best blogs I have ever read, Tess got a series of labs which give you a very good start on windbg.

Wednesday, August 06, 2008

Convention over configuration( The name is very important in Asp.Net Mvc)

When creating mvc application, in order to have the Mvc engine to find your control and view correctly, you have to put the right name.

For example, if you want to create a Test1 control, then, you have to name your control as Test1Control, and in the Views folder, you have to create a folder created Test1 view folder to put your Test1 related views there.

This may not sound very natural to the normal asp.net developer, but you just have to do that way…

Also, to properly map a method in control to one particular view under the Test1 folder, you have to use the same name for the aspx page with the method name.

In the screenshot, if you have a “Territoris.aspx”, you have to have a Territoris method in the Test1Control class.

MVCStructure

Monday, August 04, 2008

Reading lists on windows.

A couple of books I think I need spend more time reading:

Windows via c/c++;

Advanced windows debugging;

Microsoft windows internals.

 

I have gone through the basic introductions on those books, and all of them are very excellent. I am not sure the order to read them in detail, but probably the first one will be on my top priority just because Jeff is my favorite author.

Friday, August 01, 2008

Good tutorial on three popular .Net mock framework.

Here are three popular tutorials on .Net Framework by Stephen Walther.

TypeMock

Moq

Rhino Mock

Very good tutorials on three major frameworks.