Monthly Archives: November 2010


Your hosts file acts as a precursor to dns. You can manipulate requests made to resources outside of your machine with this nifty file. Windows out of the box doesn’t have any records in your hosts file so lets add one.

This is such an important file that if you try to save it with a non-windows text editor your virus scan software might just freak out. My AVG did and tried to quarantine notepad++.

Also, in Vista or 7 you’ll have to “run as administrator” or you won’t be able to save. Run the command prompt as administrator and type notepad.exe. Then open your hosts file to see its full of comments and no actual records. If you add this line at the end of the file and save the change to your system will pick up right away.

Now go to the browser and type in and you will bring up my old wedding website. Now maybe you can see why the security measures are in place on this file. If a virus were to write to this file they could replace with a website of their choosing.

Windows servers have this file too. If you use absolute links in your website you should edit it to redirect your local url to or “localhost” This way you can avoid having to make unnecessary requests to dns. If IIS is configured with domain “bindings” modifiying your hosts file on a developer workstation will allow the developer to go to the website url “” and actually hit the QA server.

Leave a comment

Posted by on November 22, 2010 in Network Admin


Single Vs. Multi threading

Imports System.Threading

A multi-threaded app requires significantly more brainpower, testing and patience to complete than its sequential counterpart. Its my advice to make sure you get a significant performance boost and time/results ratio before tackling a huge re-write. If your teammates or the future maintainers of the app don’t have the skill set, it may cost you in the long run. Before you read I am assuming you have written single threaded applications that use functions and parameters.

To make the switch from single threaded to multi threaded code, the trick is to create classes that can be instantiated by any thread. This way you can get variables or data in and out of your routines easily. To pass a parameter into a thread you would use the overload function of thread.start().

'Single threaded version
        For Each item In todolist
'multi threaded version
        For Each item In todolist
            Dim t As New Thread(AddressOf oClass.myFunction)

Kicking it off isn’t that difficult. In that example “item” is the variable that is passed into “myFunction”. To get a variable out of the single threaded example we could just “Return” it. The multi threaded example we’ll have to catch a thrown event. Here is the myFunction wrapper “oClass” in which you can see how to define the “evtReturn”

    Public Class oClass
        Public Event evtReturn(ByVal RetVal As String)
        Public Sub myFunction(ByVal myInput As String)
            'Do Stuff
            Dim myOutput as string = myInput
            RaiseEvent evtReturn(myOutput)
        End Sub
    End Class

The definition of the “FinishedWithAThread” routine has an important part “Handles oClass.evtReturn” These events may come back simultaneously so we have to use caution. This is a good time to use “synclock” to prevent an IO exception.

Sub FinishedWithAThread(ByVal myFunctionReturn as string) Handles oClass.evtReturn
        SyncLock GetType(oClass)
            File.AppendAllText("output.txt", myFunctionReturn & System.Environment.NewLine)
        End SyncLock
End Sub

With this newly acquired skill it will be fairly easy to grind any CPU into the ground. If you are writing an app for a server with multiple users, you may not even need to multi thread because the users are doing that for you. Then again, if that same server has 256 cores…. give it all you’ve got.

1 Comment

Posted by on November 16, 2010 in .NET


PHP == Hypertext PreProcessor

PHP is the open source nemesis of ASP. A completely free and viable option for writing dynamic web pages. Team it up with Apache and MySQL and you are AMPed up for success. PHP is a server side object oriented language. It is often refereed to as a scripting language but it has evolved to much more than simple scripts.

Type something into the address bar and you make an HTTP request. Instead of a normal HTML page, php code can be inserted and parsed before the response is sent to the clients browser. This lets you manipulate what the client sees instead of a boring static page you can enrich it with dynamic content.

If you are a developer, the first two useful tasks you will probably complete is the ability to process html forms and query a database. Do all PHP developers a favor and validate your form input. This is one of the many keys to a secure application. PHP gets a bad rap because it is an easy tool to use so it attracts a larger proportion of amateur developers.

Not much of a developer, use php by accessing the enormous library of tools such as WordPress, phpBB, phpMyAdmin, drupal and many more. In a LAMP scenario, setup is as simple as “apt-get”. Use this in linux to install new software on your free server.

Leave a comment

Posted by on November 8, 2010 in Uncategorized


SQL Server Database Mirroring

This feature available in Enterprise editions of SQL server is saweeeeet. It makes sense that its only in the enterprise version because most average joes wouldn’t have a need for a 100% uptime database. Yes that is 100% as in absolutely no lost transactions even when patching windows.

If you have three instances of sql server ready and a very important database mirroring can be setup in a matter of minutes… that is if you have already figured out all the setup quirks.

Before you dive in make sure you can at least make a connection string change in the application. You’ll need to set the Failover Partner=Whatever; Secondly, the application will have to be aware that mirroring is enabled and know to retry quires and connections for the few seconds it takes to failover. And for you really quick thinkers, if you are going to retry a transaction you need to also be able to know that it won’t get committed twice.

So enough about your important application that needs to be up all day and night, lets talk about setup. Here is the quick rundown:

1. take full backup
2. take log backup
3. restore full to 2nd server
4. restore log to 2nd server (don’t recover just yet)
5. make sure you have a mirroring user id
6. prinicipal database->properties database mirroring
7. configure security wizard (principal, mirror, witness)
8. open new sql ports in the firewall (5023 etc.)
9. start mirroring

When naming your servers don’t make the mistake of calling one “principal” and one “witness” as these are relative. When a failover occurs either by clicking the button or automatically via the witness the roles of the databases are changed. Also, mirroring is at the database level so you could have a handful of mirrors and a handful of principal databases on the same server.

To understand a bit better lets follow the high safety transaction.

1. user clicks submit in your app
2. app tries to open connection
3. app tries query
4. database server completes transaction on principal
5. sends transaction to mirror
6. principal sends response to user “success”

So lets say inbetween 3 and 4 someone has a typo in their remote shutdown command and kills your principal server

1. user clicks submit
2. app opens conn
3. app tries query
4. query times out
5. app check conn (closed)
6. app opens conn ( fail loop / wait 1 second )
7. witness notices principal is down and fails over
8. app opens conn to mirror which is now set to principal
9. transaction committed successfully OR primary key error and transaction already committed
10. return success

Now that you have done the necessary slapping upside the head, you bring your principal back online. The witness automatically recognizes this and sets it to mirror. Now, the new principal database copies all the transaction from the point it took over to the mirror database and just like a magic trick you mirroring session is back.

Leave a comment

Posted by on November 3, 2010 in SQL Admin