Probably we are all using "@@SERVERNAME" variable for geting SQL Server name and usually it does what we expect.
Today some custom maintenance procedures stoped working. After investigation I've noticed that SELECT @@SERVERNAME returns "NULL".
Background: @@SERVERNAME gets value (at SQL Server boot) from table sys.servers where server_id is equal to 0.
SELECT [name] FROM sys.servers WHERE server_id = 0
in this system table there are also linked servers and "my server" was there with server_id different than zero.
Solution:
EXEC master.dbo.sp_dropserver @server=N'serverName', @droplogins='droplogins'
EXEC sp_addserver 'serverName', LOCAL
and restart server.
Good workaround (probably best practice) is to use function ServerProperty('serverName').
More info at: http://randyjean.blogspot.com/2005/11/sql-servername-can-sometimes-return.html
PS Server is SQL Server 2005 Standard
Today some custom maintenance procedures stoped working. After investigation I've noticed that SELECT @@SERVERNAME returns "NULL".
Background: @@SERVERNAME gets value (at SQL Server boot) from table sys.servers where server_id is equal to 0.
SELECT [name] FROM sys.servers WHERE server_id = 0
in this system table there are also linked servers and "my server" was there with server_id different than zero.
Solution:
EXEC master.dbo.sp_dropserver @server=N'serverName', @droplogins='droplogins'
EXEC sp_addserver 'serverName', LOCAL
and restart server.
Good workaround (probably best practice) is to use function ServerProperty('serverName').
More info at: http://randyjean.blogspot.com/2005/11/sql-servername-can-sometimes-return.html
PS Server is SQL Server 2005 Standard
Also seen on SQL 2008 R2
ReplyDelete