Recognizing if SQL Server is installed (and what version)

R

Rico

Hello,

I have an application which I'd like to determine if SQL Server is
installed, and if so, what version. Is there any way to do this outside of
error trapping?

Thanks!
Rick
 
R

rowe_newsgroups

Not sure if it will work, but you could scan the registry, or even
search harddrive for the exe. It would probably be quicker to to just
use error checking though.

Just my 2 cents,

Seth Rowe
 
T

Theo Verweij

Try to connect with a sqlconnection to (local) using integrated security
If it fails to connect, it is not installed, or the current user has no
rights to connect (check error).
If it is connected, you can read the version from the ServerVersion
property.
 
R

rowe_newsgroups

This is probably the only "prpper" way to do this. Unfortunately, the
OP said he didn't want to do any error trapping (which I assumed meant
he didn't want to try to connect to the server) - but I say "to bad!"
:)

Thanks,

Seth Rowe
 
T

Theo Verweij

I never understand the questions where the "programmer" doesn't want to
use exception handling. I always wander what such applications look like
(and how they work) ....
 
H

HKSHK

Dear Rick,

To check if SQL Server is installed, you can check if this registry key
exists: HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Microsoft SQL Server

For the version, I'm not sure since I don't have different versions of
SQL Server installed.
On my computer, the registry path
HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Microsoft SQL
Server\80\Tools\Client Setup\Current Version
exists. In this key, you can read the string "CurrentVersion". In my
case it's 8.00.194.

Best Regards,

HKSHK
 
R

rowe_newsgroups

The only reason is to avoid them is because try catch statements can
add a lot of overhead if used excessively.

Thanks,

Seth Rowe
 
T

Theo Verweij

Agreed.

You only use these constructions when needed.
It is better to avoid exceptions where possible, by doing the proper
checks before executing the statements. But there will always be
exceptions in a program that must be handled.

The problem I detect in the question of Rick, is that he is using the
word "Error trapping", instead of exception handling; an exception is
not always an error.

The problem with another way of SQL Server checking(like the registry
way provided in the reply of HKSHK) is that the registry entries are
changing when new versions of SQL Server are released; SQL 2000 version
is stored in Microsoft SQL Server\80, SQL 2005 in Microsoft SQL
Server\90, SQL 7 in Microsoft SQL Server\70, SQL 6.5 - I don't know. And
maybe the next version will use a complete other path, or even no
registry settings at all. Another problem is that you may know that it
is installed, and what version it is, but if you don't know if it is
running (or if the user has the right to connect to it) you still have
to apply a try catch block to a connection to this instance.
 
K

kosecki

Rico napisal(a):
Hello,

I have an application which I'd like to determine if SQL Server is
installed, and if so, what version. Is there any way to do this outside of
error trapping?

Thanks!
Rick

Hi, i use this code to check about running instances, which can also
provide information about version. I know it's not 100% what you
looking for, but perhaps will be useful:


Imports System.Data.Sql
Public class test
Private _list_inst As SqlDataSourceEnumerator

Public Property list_inst() As SqlDataSourceEnumerator
Get
Return _list_inst
End Get
Set(ByVal value As SqlDataSourceEnumerator)
_list_inst = value
End Set
End Property

Private Function listservers() As DataTable
list_inst = Sql.SqlDataSourceEnumerator.Instance
Return list_inst.GetDataSources
End Function
end class

Function listservers return datatable with current installed and
running (!) instances. There is column called version.

Greeting
PK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top