Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Wrong Server Name

enter image description hereI am executing a query from which i want to get all server name installed on a system
So I did it with this query

select srvname  from sysservers    

It gives me server names but it is not the correct server name it gives me srvname

WIN-1BKHGVK7J3A\SQLSERVER2008R2

but this is not my server name also i tried to do it from another way by this query

Select @@Servername   

it also gives above wrong server name WIN-1BKHGVK7J3A\SQLSERVER2008R2

But when i did it with this query

SELECT SERVERPROPERTY ('ServerName')  

it gives correct server name which is AIS-OCTACORE\SQLserver2008r2
but limitation with this is it only gives current server name and i want to get all server name installed on a system
can you please tell why i'm getting wrong servername??
Also how could i get all server names

like image 932
Amit Bisht Avatar asked Jan 08 '14 10:01

Amit Bisht


2 Answers

To check what the current values are set to

SELECT ServerProperty('machinename') as [machinename]
    ,ServerProperty('ServerName') as [ServerName]
    ,@@ServerName as [@@ServerName];

To correct the issue run the following:

EXEC sp_dropserver 'old_server_name';
GO

EXEC sp_addserver 'new_server_name', 'local';
GO

You will need to restart the SQLSERVER service

like image 107
Andrej Hribernik Avatar answered Sep 29 '22 17:09

Andrej Hribernik


This can happen when the server name is changed after SQL Server was installed.

You could try sp_dropserver and sp_addserver to change it back: http://www.brentozar.com/blitz/servername-not-set/

Im not sure i would though you dont know why it was changed in the first place it might break something.

like image 45
DaImTo Avatar answered Sep 29 '22 16:09

DaImTo