Check if SQL instance exists
Posted: Fri Nov 30, 2012 6:12 am
Hello,
I need to check if a given sql server instance already exists on the local machine.
Since I already needed the list of available servers elsewhere, my first approach was to check if the string containing the available instances contains the requested instance name. Failed. The string contained the name, but the function returned false.
Next approach: Splitting the string containing the names by $NEWLINE$ and check if the collection contains the requested name: Failed.
Next one: Replace all occurences of $NEWLINE$ with ยต... a character most probable not used for an instance name and checking... Failed.
Next try: Set variable $SERVICENAME$ to MSSQL$$MYREQUESTEDINSTANCENAME$ and checking if this service runs on the local machine... failed.
Since the instance could be sql2008 as well as sql2005 I cannot simply check the registry for HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\InstalledInstances or HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL because sql 2005 instances are not listed there.
The desired usage: A user should be able to provide a name for a new sql server instance. The Next button of this wizard step should be disabled when an instance with the provided name already exists.
Suggestions?
Thanks in advance!
EDIT: I got the service approach working. How can I utilize the result to enable/disable the NEXT button depending on the content of a textbox being an instance?
For example: An instance with the name MYINSTANCE exists on the server. When the user types MYINST the Next button should be enabled... when he types MYINSTANCE it should change to disabled, when he continues and types MYINSTANCEX it should be enabled again.
I need to check if a given sql server instance already exists on the local machine.
Since I already needed the list of available servers elsewhere, my first approach was to check if the string containing the available instances contains the requested instance name. Failed. The string contained the name, but the function returned false.
Next approach: Splitting the string containing the names by $NEWLINE$ and check if the collection contains the requested name: Failed.
Next one: Replace all occurences of $NEWLINE$ with ยต... a character most probable not used for an instance name and checking... Failed.
Next try: Set variable $SERVICENAME$ to MSSQL$$MYREQUESTEDINSTANCENAME$ and checking if this service runs on the local machine... failed.
Since the instance could be sql2008 as well as sql2005 I cannot simply check the registry for HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\InstalledInstances or HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL because sql 2005 instances are not listed there.
The desired usage: A user should be able to provide a name for a new sql server instance. The Next button of this wizard step should be disabled when an instance with the provided name already exists.
Suggestions?
Thanks in advance!
EDIT: I got the service approach working. How can I utilize the result to enable/disable the NEXT button depending on the content of a textbox being an instance?
For example: An instance with the name MYINSTANCE exists on the server. When the user types MYINST the Next button should be enabled... when he types MYINSTANCE it should change to disabled, when he continues and types MYINSTANCEX it should be enabled again.