3

I'm looking for a way to identify a particular SQL Server Instance from a stored procedure within the server. What I need is to be sure that my app is connecting to that particular instance and not to some other instance with the same name/ip address.

0

4 Answers 4

1

I'd take a look at the SERVERPROPERTY function - you could use a mixture of InstanceName, MachineName, ServerName or ProcessID for example.

Sign up to request clarification or add additional context in comments.

Comments

1

You should look at using the @@SERVICENAME function.

Here's the description from the @@SERVICENAME MSDN article

Returns the name of the registry key under which SQL Server is running. @@SERVICENAME returns 'MSSQLSERVER' if the current instance is the default instance; this function returns the instance name if the current instance is a named instance.

The @@SERVERNAME will return the name of the server the database is running on, which may also be helpful to you.

Usage example: SELECT @@SERVERNAME as 'Server Name', @@SERVICENAME AS 'Service Name'

Comments

1

You can write:

select  @@ServiceName

Comments

0

Sometimes, the instance id can be seen under following folder path

%programfiles%\Microsoft SQL Server\<instance-id>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.