SQL SERVER – Find Name of The SQL Server Instance

Few days ago, there was complex condition when we had one database on two different server. We were migrating database from one server to another server using nightly backup and restore. Based on database server stored procedures has to run different logic. We came up with two different solutions.

1) When database schema is very much changed, we wrote completely new stored procedure and deprecated older version once it was not needed.

2) When logic depended on Server Name we used global variable @@SERVERNAME. It was very convenient while writing migrating script which depended on server name for the same database.

Syntax:

SELECT @@SERVERNAME AS 'Server Name'

ResultSet:
Server Name
——————–
SQLAUTHORITY

Reference : Pinal Dave (https://blog.sqlauthority.com)

SQL Scripts, SQL Utility
Previous Post
SQL SERVER – 2005 – OUTPUT Clause Example and Explanation with INSERT, UPDATE, DELETE
Next Post
SQL SERVER – 2005 – Explanation of TRY…CATCH and ERROR Handling With RAISEERROR Function

Related Posts

35 Comments. Leave new

  • Thanks

    That helped me, Very useful

    Reply
  • oh, nice post.
    thanks…

    Reply
  • Thank you for the post

    Reply
  • After changing the server name, the @@SERVERNAME still returns the old server name, any idea where @@SERVERNAME is stored so that I can update it to reflect the new server name?

    Reply
  • After changing the server name, the @@SERVERNAME still returns the old server name, any idea where @@SERVERNAME is stored so that I can update it to reflect the new server name?

    It seems that SERVERPROPERTY(‘servername’) returns the new name of the server.

    Reply
  • Imran Mohammed
    July 24, 2009 8:55 am

    @Goerge

    Did you restart your SQL Server Instance after you changed name?

    Also is it a default instance or named instance ?

    ~ IM.

    Reply
  • Yes, we restarted the default instance after renaming the server.

    I’m not sure why the @@SERVERNAME has the old name, but at least the SERVERPROPERTY(‘servername’) returns the new server name.

    Reply
  • how to connect sql server 2008 and i don’t know server name of this, how to find before connecting.

    Reply
  • how to connect sql server 2005 and i don’t know server name of this, how to find before connecting.

    Reply
  • An error has occured while establishing a connection to server.when connecting to sql server 2005,this failure may be caused by the fact that under the default setting sql server does not allow remote connection ,(provider:Named pipes provider,error:40-could not open a connection to sql sever )(Microsoft sql server error;53)

    Reply
  • That command gives you the server instance name which is only helpful if it is the name of the server. If you are in a clustered environment of want the actual physical name of the server run this…

    SELECT SERVERPROPERTY(‘ComputerNamePhysicalNetBIOS’);

    Reply
  • That command gives you the server instance name which is only helpful if it is the name of the server. If you are in a clustered environment of want the actual physical name of the server run this…
    This only works on SQL 2005 and above though.

    SELECT SERVERPROPERTY(‘ComputerNamePhysicalNetBIOS’);

    Reply
  • The problem arises on Windows 2008. SELECT SERVERPROPERTY(‘ComputerNamePhysicalNetBIOS’) will return SQL virtual name rather then physical node name.

    Reply
  • How can i know my SQL server name?
    Please give me some idea about SQL server…

    Reply
  • pls help me i’m using windows 7 professional
    i’m getting this error when i connect to sql server..
    ADDITIONAL INFORMATION:

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)

    Reply
  • hi,

    how can i find the server name from the run command…?
    Can i get the command plz…….

    Reply
  • pls help me i’m using windows 7 enterprise
    i’m getting this error when i connect to sql server..
    ADDITIONAL INFORMATION:

    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)

    Reply
  • I have the same error message :
    ” A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)”
    Can anyone help me

    Reply
  • A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)
    i am trying to connect to sql server from asp.net page i am getting this error.my server name-NISHITHA-PC\SQLEXPRESS that is local system . i am using sql server 2005
    what is the proble

    Reply
  • chandrashekhar
    May 11, 2012 8:00 pm

    how to find out ms sql management studio express 2005 server name

    Reply

Leave a Reply