views:

183

answers:

1

I am using DbConnection.GetSchema("Databases") to retrieve a list of databases from a given connection, and that works as expected. However i want to sort out the system db's from this list, as they are not valid for what i intend to do with this list.

Does anyone know a way to do this?

A: 

UPDATE

Can only restrict by Name when retrieving information from the "Databases" meta-collection using GetSchema(), which will NOT allow you to filter out System DBs.

There is an overload that allows you to specify a list of restrictions on the data returned, which should allow you to filter out System DBs:

DbConnection.GetSchema(String, String[])

Documentation on Restrictions

How to use the method in practice

Amal Sirisena
Yes, i know those links! Unfortunatly the only restriction available for the databases schema is the name. Have i missed something?
Argo
No you are right, I assumed you would have the ability to restrict the Databases based on more than Name, but it does not seem like you can. If you are using SQL Server 2005 / 2008, you could retrieve the info you want from a system view using a query similar to: SELECT * FROM sys.databases where owner_sid <> 0x01
Amal Sirisena
Or SELECT * FROM sys.sysdatabases where sid <> 0x01 on SQL Server 2000. I am not familar with other RDBMS systems but I would presume they provide similr system objects you could use.
Amal Sirisena