0

Possible Duplicate:
How can I determine installed SQL Server instances and their versions?

i've been searching and cannot find a way to verify through the registry if the sql server is installed and at least is the 2008 one. Because it seems that for every version they change something in the path or i just didn't see it.

Thank You in advance, Miguel Sousa

Community
  • 1
  • 1
Miguel de Sousa
  • 324
  • 2
  • 15
  • im sorry but its not the same thing. 1º i want to know if the version of sql server is 10.0(thnx @AaronBertrand) or newer. 2º i don't have the login access to the instances. so i cant execute t-sql nor ado.net – Miguel de Sousa Jun 15 '12 at 12:46

1 Answers1

2

You can scan for instance names in the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL\

From there you can take each name and the data column (e.g. a named instance 'SQL2008' might say 'MSSQL10.SQL2008'), and find the version by appending the instance identifier ('MSSQL.SQL2008') to this reg path:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\
  MSSQL10.SQL2008\MSSQLServer\CurrentVersion\

In that key, there will be an entry called "CurrentVersion" and the data value will have the version #.

This will return a string like 11.0.2316.0. In this case you only really care about the characters before the second decimal. If this reflects 10.0 or greater, that's SQL Server 2008 or greater (10.0 = 2008, 10.5 = 2008 R2, 11.0 = 2012). If this reflects 9.0 or less, that's something before 2008 (9.0 = 2005, 8.0 = 2000, etc).

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
  • This assumes there is an active database connection; that is a few steps _after_ determining **whether** SQL server is installed. – CodeCaster Jun 15 '12 at 12:29
  • @AaronBertrand im sorry i should have been more specific, i dont have access to the server, cause i dont know if its installed, so i can't execute T-SQL. – Miguel de Sousa Jun 15 '12 at 12:30
  • Ah, I missed that part. Ok, yes you can't use T-SQL because even if you do determine that an instance is installed, you may not be able to connect to it at all. I think you will get sufficient answers then but you'll need to go to both http://stackoverflow.com/questions/141154/how-can-i-determine-installed-sql-server-instances-and-their-versions and http://stackoverflow.com/questions/949852/determine-version-of-sql-server-from-ado-net and combine some answers. – Aaron Bertrand Jun 15 '12 at 12:31
  • is it possible if sql server is unisntall there would be the registry left of the instances??? i mean would exist after is uninstalled 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names' – Miguel de Sousa Jun 15 '12 at 12:33
  • Sure, I think if a proper uninstall is performed that registry stuff should be cleaned up, but it's possible that people don't remove SQL Server the right way. It's also possible that a SQL Server instance is installed but it's not running, or can't start for various reasons, or you can't connect to it via Windows auth, or the user can't even connect to it manually because they're not a member of admin and they've forgotten the sa password. So presence in the registry is certainly not an indication that a SQL Server instance is up and running and available for use. – Aaron Bertrand Jun 15 '12 at 12:41
  • ok thank you @AaronBertrand, is there any other way that i can know if the sql server is installed without the previous options? – Miguel de Sousa Jun 15 '12 at 12:56
  • Registry should be the best / most reliable option to determine if it is installed. You'll still want to look at the other questions you've been pointed to - I agree your question is not identical but the answers there still might be helpful to you. – Aaron Bertrand Jun 15 '12 at 13:02