Thursday, July 28, 2011

SELECT @@SERVERNAME, it may return NULL / Wrong Server name

when you run SELECT @@SERVERNAME, it may return NULL / Wrong Server name.

Whenever you change the Network Name of Server Name, @@SERVERNAME does not report such changes. @@SERVERNAME reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure.

To confirm do the following:
SELECT @@SERVERNAME
select SERVERPROPERTY('MACHINENAME')
If the two above outputs shown different name means do the following:

To make SELECT @@SERVERNAME reflect the new changed Network Name perform the below task.

USE master
GO
EXEC sp_dropserver 'OLDSERVERNAME'
GO
EXEC SP_addserver 'NEWNETWORKNAME','LOCAL'
GO
Once done please restart the SQL Services and then Query SELECT @@SERVERNAME.

Wednesday, July 20, 2011

enabling DeadLoack trace on SQL Server

BEGIN
DBCC TRACEON (1204, 3605, -1)
WAITFOR TIME '23:30';
DBCC TRACEOFF (1204, 3605, -1)
END