Figuring sql server version via code

J

John

Hi

Is it possible to check in .net;

1. If sql server 2008 express is installed on a machine?

2. The name of sql server 2008 express instance or instances?

3. If a particular sql server 2008 express instance contains a specific
database?

Many Thanks

Regards
 
M

Michael Coles

J

Jay Konigsberg

1. If sql server 2008 express is installed on a machine?> 2. The name of
sql server 2008 express instance or instances?

SELECT
SERVERPROPERTY ('ProductVersion') ProductVersion
, SERVERPROPERTY ('ProductLevel') ProductLevel
, SERVERPROPERTY ('Edition') Edition
, SERVERPROPERTY ('ServerName') ServerName
, SERVERPROPERTY ('InstanceName') InstanceName

and
3. If a particular sql server 2008 express instance contains a specific
database?

SELECT QUOTENAME(sdb.name)
FROM master.dbo.sysdatabases sdb
WHERE status & 32 != 32
AND status & 64 != 64
AND status & 128 != 128
AND status & 256 != 256
AND status & 512 != 512
AND status & 1024 != 1024
AND status & 4096 != 4096
AND status & 32768 !=32768

The where clause is to eleminate stuff like offline db's and whatnot.

--
Jay Konigsberg
SQL Server DBA in Sacramento, CA
http://www.linkedin.com/in/jaykonigsberg

Live in Sacramento, CA?
Join the Sacramento SQL Server User Group on LinkedIn
http://www.linkedin.com/groups?home=&gid=2825448&trk=anet_ug_hm&goback=.myg
 
G

Gregory A. Beamer

John said:
Hi

Is it possible to check in .net;

1. If sql server 2008 express is installed on a machine?

2. The name of sql server 2008 express instance or instances?

3. If a particular sql server 2008 express instance contains a specific
database?

Many Thanks

You can do all of this with SMO (or DMO in COM based apps, SMO is a .NET
replacement). Do a google search on SMO and you will see how to check SQL
instances, versions, etc. It has a nice method to iterate through all
instances of SQL on a box.

As for databases, you need to be able to connect with an account with
permissions to ask the question. If not, your questions (statements) will
fall on empty ears, so to speak. If you don't have permissions, you can try
to query the database in question, and if you have those rights, you will
either get an exception (does not exist) or an answer. That is a crude, last
ditch effort, of course.

--
Peace and Grace,
Greg

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

************************************************
| Think outside the box! |
************************************************
 

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