user1361455
user1361455

Reputation: 33

SQL Server Instance ID

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.

Upvotes: 3

Views: 22842

Answers (4)

LCJ
LCJ

Reputation: 22652

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

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

Upvotes: 0

Royi Namir
Royi Namir

Reputation: 148514

You can write:

select  @@ServiceName

Upvotes: 1

Adam Porad
Adam Porad

Reputation: 14471

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'

Upvotes: 1

Bridge
Bridge

Reputation: 30651

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

Upvotes: 1

Related Questions