@@servername ????????? empty output

  • Strange thing happen....

    I have been using an sql code that include @@servername to retrieve name of local server.

    I tried this on several SQL server and it works, but after others test I have found out an error during batch process......the error occur because in an sql server the system variable @@servername was empty.

    I run the statement print @@servername and the output was empty ....

     

    anyone knows why in some sqlservers @@servername is an empty string ?????? 

     

    thank a lot

     

  • possible that master db is corrupted.

    if you have a backup of master db , restore it.

  • try using:

    select serverproperty('servername')

    if this is different to @@servername you need to use sp_addserver to make the output the same.

     

     

    regards,

    Mark Baekdal

    MSN m_baekdal@hotmail.com

    +44 (0)141 416 1490

    +44 (0)208 241 1762

    http://www.dbghost.com

    http://www.innovartis.co.uk

    Build, Comparison and Synchronization from Source Control = Database change management for SQL Server

     

     

     

  • After using sp_addserver, you'll have to stop, then restart, SQL Server.

    EXEC sp_dropserver 'yourServerName'

    EXEC sp_addserver 'yourServerName', 'local'

    Stop SQL Server.

    Restart SQL Server.

    Also, try either or both of these:

    EXEC sp_helpserver

    and

    SELECT srvid

         , srvname

         , datasource

         , srvnetname

     FROM master..sysservers

  • I would suggest to replace

    EXEC sp_dropserver 'yourServerName'

    with

    EXEC sp_dropserver 'yourServerName,'droplogins'

  • anyone knows why in some sqlservers @@servername is an empty string ?????? 

    This happens when the server is renamed

    Read previous post for the solution!

     


    * Noel

  • On named instance

    SELECT @@servername

    gives NULL

     


    Kindest Regards,

    Tahir

  • On named instance

    SELECT @@servername

    gives NULL

     


    Kindest Regards,

    Tahir

  • After executing sp_adderver ...,local you need toi stop/restart SQL Server.

     

    Just a little 'undocumented feature' that's been around since v4.21 ...

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • That is not correct! I have a named instance in my development computer an it gives me : COMPUTERNAME\INSTANCENAME

     


    * Noel

  • Thank to everybody,

    added local server and stop/restart server .......OK

  • Thanks dear

    EXEC sp_addserver 'servername', 'local'

    works just fine.

     


    Kindest Regards,

    Tahir

  • Thank to everybody.......

     

  • Thanks for the suggestion about using EXEC sp_dropserver 'yourServerName,'droplogins'.

    We were just trying to use EXEC sp_dropserver 'yourServerName without the droplogins directive and received errors about a linked server (another developer was using the system with permission).

    Dropping the server, re-adding it (sp_addserver...), stopping and re-starting the service corrected the issue.

    Now we also get the correct server_id = 0 for the SQL instance in sys.servers (or srvid = 0 in master.dbo.sysservers).

    Argue for your limitations, and sure enough they're yours (Richard Bach, Illusions)

Viewing 14 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic. Login to reply