snippetsqlMinor
How to uniquely identify SQL instance
Viewed 0 times
sqlidentifyinstanceuniquelyhow
Problem
I need to find a way how to identify SQL Instance no matter what changes were done to SQL Server and\or Windows Server where it is running, because we're collecting remotely information about instances into our operational database and still encountering way we're identifying it is not that unique as it might look.
In example, if I have server WIN1\SQL and due to server refresh will install on different server WIN2\SQL, migrate data and swap server names so that WIN2\SQL will become WIN1\SQL and vice versa, I need to be able identify that current WIN1\SQL is different from previous WIN1\SQL disregards OS version and or SQL version\patch level
Already tried following:
NetworkName\InstanceName - that worked until server hostname\network name has been changed due to server refresh as described above
SQL Server SID - I was searching for some SID of SQL Installation like Windows has, but seems nothing like that really exists
SID of ##MS_SQLAuthenticatorCertificate## - this was last best shot I found, scanned hundreds of SQL Servers and it was really unique - thought I found it finally, until I applied Service Pack to one server and find out SID has changed
Any idea how to uniquely identify SQL Instance (like SQL Instance SID) would be appreciated, because I'm getting lost
EDIT: I'm not administrating all SQL servers. Modifications on out of scope devices cannot be done, thus looking for some "already built-in" way that would work on SQL2005+
In example, if I have server WIN1\SQL and due to server refresh will install on different server WIN2\SQL, migrate data and swap server names so that WIN2\SQL will become WIN1\SQL and vice versa, I need to be able identify that current WIN1\SQL is different from previous WIN1\SQL disregards OS version and or SQL version\patch level
Already tried following:
NetworkName\InstanceName - that worked until server hostname\network name has been changed due to server refresh as described above
SQL Server SID - I was searching for some SID of SQL Installation like Windows has, but seems nothing like that really exists
SID of ##MS_SQLAuthenticatorCertificate## - this was last best shot I found, scanned hundreds of SQL Servers and it was really unique - thought I found it finally, until I applied Service Pack to one server and find out SID has changed
Any idea how to uniquely identify SQL Instance (like SQL Instance SID) would be appreciated, because I'm getting lost
EDIT: I'm not administrating all SQL servers. Modifications on out of scope devices cannot be done, thus looking for some "already built-in" way that would work on SQL2005+
Solution
Well, it is somewhat possible to have an Instance GUID, but only if you are including
It will be different across each instance, but should be consistent across restores of backups of the same
If you want to create new SQL Server instances from a "master" set of backup files (including
NOTES:
-
The
-
If you are using this technique to distinguish instances of SQL Server Express LocalDB, then the the
[msdb] in your backup / restore process. Assuming that this is indeed the case, then just check the service_broker_guid field in sys.databases for the [msdb] database:SELECT [service_broker_guid]
FROM sys.databases
WHERE [name] = N'msdb';
It will be different across each instance, but should be consistent across restores of backups of the same
[msdb] database. This even appears to hold true for the Express editions. And while I have not tracked this value across updates and Service Packs, I don't see why it would change unless forced to manually.If you want to create new SQL Server instances from a "master" set of backup files (including
[msdb]) and need the new instances to be seen as different, then just run the following after the initial restore of the system databases:ALTER DATABASE [msdb] SET NEW_BROKER;
NOTES:
-
The
service_broker_guid field in sys.databases for the [master] and [model] databases is always set to 00000000-0000-0000-0000-000000000000 and cannot be changed via ALTER DATABASE [{database_name}] SET NEW_BROKER;.-
If you are using this technique to distinguish instances of SQL Server Express LocalDB, then the the
service_broker_guid field in sys.databases for the [msdb] database will initially contain the same value for all newly created instances. In this case, you just need to execute ALTER DATABASE [msdb] SET NEW_BROKER;, just like when creating new instances from a backup restore.Context
StackExchange Database Administrators Q#103347, answer score: 4
Revisions (0)
No revisions yet.