From: John on
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


From: Michael Coles on
You can use several methods to enumerate SQL Server instances. Here are a
couple:

http://msdn.microsoft.com/en-us/library/a6t1z9x2.aspx
http://www.sqldbatips.com/showarticle.asp?ID=45

To determine whether a specific instance contains a certain database, you
can connect to the instance's master database and query the sys.databases
catalog view.

--
Thanks

Michael Coles
SQL Server MVP
Author, "Expert SQL Server 2008 Encryption"
(http://www.apress.com/book/view/1430224649)
----------------

"John" <info(a)nospam.infovis.co.uk> wrote in message
news:%23ZY3QcHyKHA.2552(a)TK2MSFTNGP04.phx.gbl...
> 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
>
>

From: Jay Konigsberg on
> 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=%2Emyg



"John" <info(a)nospam.infovis.co.uk> wrote in message
news:%23ZY3QcHyKHA.2552(a)TK2MSFTNGP04.phx.gbl...
> 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
>
>


From: Gregory A. Beamer on


"John" <info(a)nospam.infovis.co.uk> wrote in message
news:#ZY3QcHyKHA.2552(a)TK2MSFTNGP04.phx.gbl...
> 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! |
************************************************