Error Handling in SQL 2000 is depressing

The whole buisness of error handling in sql server 2000 stored procedures is depressing.

For example if a query has an incorrect table structure then there is no way of handling that from within the sp.  

It is rather inconsistent, the best that can be acheived is a compromise. You have to check @@ERROR after every step.

I hope that SQL Server 2005  will be better once I am allowed to use it.

SQL Server Oddity and a fix.

Recently I found that @@SERVERNAME does not actually return the name of the server that the machine is running.

It returns the name that was last set using sp_addserver ‘NAME’, local

This makes a difference if you are  creating an image of a machine as a master copy.
All of the copied machines will think that they are the master machine.

The following script should detect and repair incorrect server names:

SET NOCOUNT ON

DECLARE @OLDNAME VARCHAR(200)
DECLARE @NEWNAME VARCHAR(200)

SELECT @OLDNAME = @@SERVERNAME
SELECT @NEWNAME = CAST( SERVERPROPERTY(‘ServerName’) AS VARCHAR(200))

select @OLDNAME, @NEWNAME

IF @OLDNAME <> @NEWNAME
BEGIN
    PRINT ‘Server name differs’
    IF @NEWNAME IS NOT NULL
    BEGIN
        IF @OLDNAME IS NOT NULL
        BEGIN
            PRINT ‘Dropping server ‘ +  @OLDNAME          
            EXEC sp_dropserver @OLDNAME
            PRINT ‘Dropped server ‘ +  @OLDNAME          
        END
        PRINT ‘Adding server ‘ + @NEWNAME
        EXEC sp_addserver @NEWNAME, ‘local’
        PRINT ‘Added server ‘ + @NEWNAME
        PRINT ‘Now stop and restart SQL Server’
    END
END

Old School HTTP: Impersonate a browser with Telnet

I have been having fun lately at work getting a public website hosted on a webserver inside a firewall sharing the same server (port and ip address) as other websites.

The IIS config is outside the scope of this post (Hint: HOST HEADER NAME should match the website name, for example http://www.google.com).

Also outside the scope is setting up a firewall/router to map the external ip address to the internal server address.

What I am going to discuss is the use of Telnet to impersonate a web browser.  This can be very useful to determine if you actually have got your website working and you are just waiting for the DNS entries to be propigated.

I am going to use google as an example (you would need to substitute your own site and ip address).

First I will find the ip address of google (it may have changed since this article was written).

At a command prompt type:

ping http://www.google.com

This should respond pinging google.com [64.233.167.99]

 

At a command prompt type:

telnet 64.233.167.99 80

GET / HTTP/1.1

Host: http://www.google.com

{Hit enter x3}

This should respond with some text.

It will start with:

HTTP/1.1 and then be followed (after some header details) with the html body of your website. 

If this works then you know that all you have to do is wait for the DNS records to be updated.