Thursday, January 24, 2013

SQL Server installation Unknown error (0xfffffff)

I’ve seen this problem so many times. The hard part is that the error is not meaningful, and there is no additional info in EventViewer or SQL installation logs. The problem is GPO policy. Basically someone set a policy for AD not to allowed users to run applications called
You need to disable it in regedit tool, goto:
And rename setup.exe to something like setupzzz.exe

No IIS manager after adding IIS role to Microsoft Server 2008 R2

For some weird reasons sometimes when I add IIS role to Microsoft Server 2008, IIS Manager is not installed automatically. It needs to be installed by adding IIS Management Console Service Role.

Tuesday, January 22, 2013

IIS 7.5 application path for web.config problem

A very interesting error is displayed when selecting a WebSite and trying to set its configuration under IIS. If you select a Site under IIS Manager, you should be able to modify configuration from within IIS Manager. For example by selecting 'Error Pages'. But when I tried to click on any of configuration Icons I received a following message: There was an error while performing this operation. Filename: \\?\C:\inetpub\web.config
It was weird because the path for web.config was correct, and IIS process had permissions to access application folder and web.config itself. The error was not meaningful at all. The problem was resolved after installing 'HTTP Redirections' Role Services for IIS.
I had to reboot my machine after that.

In an addition one needs to install a third party software called URL Rewrite (I installed version 2.0) using microsoft platform installer.

My understanding is that IIS Manager w/o some features from HTTP Redirections was unable to parse web.config correctly, and it was raising a weird exception.

Howto Register (copy) a dll in GAC under Server 2008 R2 w/o installing additional software

It was a pain. There is plenty of information in the web, but they do not target Server 2008 R2, or require installation of VS or .NET Framework 2.0 Software Development Kit (SDK). First let me just point out that gacutil when you run a command:
gacutil /i yourdll.dll
Will just copy a dll to GAC folder, so you can do it manually without gacutil, if you know how.

When you try to drag and drop a dll from one folder to GAC folder you receive a message 'Access is denied' (as in screen), or nothing seems to happen (depending on a configuration). To copy dll to GAC you need to turn off UAC (User Account Control - a thing that blocs you from doing something interesting under Server 2008) you need to:
Start->Control Panel->User Accounts->User Accounts->Change User Account Control settings

And set it to 'Never notify' (as in screen). You need to restart your machine.

After you restart it you will be able to grab and drop from any window to GAC folder.

Friday, January 18, 2013

The decimal type problem in financial word

Decimal is a typical type used in financial word, to prevent lost of information/precision during mathematical computations. There is one issue that is not put in a consideration. The C# ECMA specification guarantees that the following types will be written atomically: reference types, bool, char, byte, sbyte, short, ushort, uint, int and float. There is no decimal on that list. It means that:
class AtomicityExample {
    decimal _value;
    void SetValue(decimal value) {_value = value;}
    decimal GetValue() {return _value;}
If the code is executed by many threads, the returned value of GetValue method may be not a value that was set by a SetValue.

What is even less know is that the order of the operations in C# may change, due to .net optimization. Consider following code:
class OrderExample {
    decimal d1;
    volatile decimal d2;
    decimal d3;

    void Assign(){
        d1 = 1;
        d2 = 2;
        d3 = 3;
The assignment in a code above can happen in following ways:
d1 = 1;
d2 = 2;
d3 = 3;
d1 = 1;
d3 = 3;
d2 = 2;
d3 = 3;
d1 = 1;
d2 = 2;
In other words volatile variable can be assigned only after d1 was assigned, but when exactly depends on a compiler. Be aware that majority of programmers don't even use volatile keyword, and without volatile keyword reads/writes of variables above can happen in any order. And it matters, because I've seen so many times a code that looked like:
class FalseSecurityExample {
    decimal d1;
    bool assigned;

    void Assign(){
        d1 = 1;
        assigned = true;

    decimal Calculate(){
            return d1;
It means that in an example above d1 may not be set before it is returned, and if you add to a consideration fact that decimal is not atomic, you can expect anything to be returned by this code.

When I ask people why do they write such code, and if they are aware of issues that are illustrated above, usually they answer, that we are not writing a project for NASA, or anything like that so bug off. Interesting.

Wednesday, January 16, 2013

Disabling proxy under IE

It's easy under Firefox and Chrome, but somehow there is no option for that in IE. To turn it off, search your Registry (inside Regedit) for ProxyEnable, and set its value to 0, on my computer I found 4 matching places, and I changed all of them. Done. The hard part is that I have to do it from time to time, it means that for some reasons some process set the ProxyEnable to 1 sometime (once in month).

Monday, January 14, 2013

Application recycling

For some time I was worried about unknown behaviour of my application. By analysing perfmon logs showing memory counters of iis processes and perfmon logs for operating system basic counters, I could clearly see that something bad is going on from time to time. Basically it looks like my application was being restarted. By looking at counters it looks like there is a memory leak in app (this is a very old app, and no one knows how it really works). The thing that I did not understand was why it is restarted, or what magic clears entire memory of app. Because I do not have an access to a production it was really hard to guess by looking at few perfmon logs. The next thing that I did not understand was why there was no error or warning in a log file (or event log in OS). As an addition my failover architecture was never triggered. Failover is set up to use a loadbalancer to ping my app and if it's not able to receive a response it redirects traffic to a different server. Finally it enlightens me that by default IIS is set up to recycle app every 1740 minutes (about 29 hours). When recycling happens, a new process is created in a background to handle new requests, and an old process is allowed to finish dealing with request that he was requested to deal with, before it is terminated – that’s why app is constantly responsive. As always the simplest answer is the hardest to think of.

Saturday, January 12, 2013

Arduino Servo controling

There is a huge buzz about how to control servo from arduino in the net. Just to let people know what is a simplest solution. But first few details about servo and arduino. Servo comes with 3 cables with 3 different colors:
  • brown - needs to be connected to ground
  • red - needs to be connected to power supply +5V
  • orange - needs to be connected to control pin - thru this you will send commands to servo from arduino library.
So let's say that you connected everything as described above, and orange (data) cable is connected to a pin 5. Below is a simple code that rotates a servo waits 2s and rotates it to a different position.

Servo servoh;
int runOnce = 1;

void setup() {

void loop() {
  if(runOnce == 1){
    runOnce = 0;
    runOnce = 1;

Thursday, January 3, 2013

Reading from transaction log file - SQL Server

Sometimes I need to figure out when a certain operation happened, like when a row was deleted, or added. In order to investigate I use two tools:
DBCC LOG(databasename, typeofoutput)

where typeofoutput:
0: Return only the minimum of information for each operation -- the operation, its context and the transaction ID. (Default)
1: As 0, but also retrieve any flags and the log record length.
2: As 1, but also retrieve the object name, index name, page ID and slot ID.
3: Full informational dump of each operation.
4: As 3 but includes a hex dump of the current transaction log row.
fn_dblog runs in a context of a DB, so be sure to select the one that is interested to you. Results are ordered, the oldest are first to be displayed.
SPID,                         -- The process ID for the transaction
[Begin Time],                 -- The start time for the transaction
[Current LSN],                -- The lsn of this record           
[Previous LSN],               -- Previous lsn for this record
Operation,                    -- The operation performed by the log record
Context,                      -- The resource affected by the operation
[Log Reserve],                -- The space reserved for rollback in bytes
AllocUnitName,                -- The name a the affected allocation unit
[Page ID],                    -- The page ID of the affected page
[Number of Locks],            -- The number of locks held by the transaction
[Lock Information]            -- Information about the locks held and the resources locked
FROM fn_dblog(NULL, NULL)
The number of rows displayed depends on a Recovery Mode, if it's set to Simple, SQL server will decide how much information keep in transaction log file, if it's set to FULL, then this query will display all operations from a time when Recovery Mode was set to FULL.