@@servername

If @@servername returns null or return wrong host name, execute below mentioned sql Query.


DECLARE @Current SysName
Select @Current = Convert(varchar(128), SERVERPROPERTY(‘ServerName’) )
IF(@Current <> @@SERVERNAME)
BEGIN
EXEC sp_dropserver @@SERVERNAME
EXEC sp_addserver @server=@Current,@local = ‘local’
EXEC master..xp_cmdshell ‘ECHO NET STOP MSSQLSERVER > restartSQL.bat’, no_output
EXEC master..xp_cmdshell ‘ECHO NET START MSSQLSERVER >> restartSQL.bat’, no_output
EXEC master..xp_cmdshell ‘restartSQL.bat’, no_output
–Connection with sql break here
END

— Check if every thing is correct
SELECT @@Servername
SELECT SERVERPROPERTY(‘ServerName’)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s