Re: .NET database inspection API?
- From: "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM@xxxxxxxxx>
- Date: Sun, 27 Apr 2008 10:46:07 +0200
Peter Duniho wrote:
Is there a straightfoward API in .NET that allows for inspection of a database? That is, to look at the structure of the database, without knowing anything in advance about it? For example, retrieving a list of tables in the database.
Depends on what you want to know. If you just want to know the tables and their columns, it might be possible, using DbProviderFactory to obtain the factory for the db elements at hand, and then use these elements, e.g. command, connection, to obtain the schema of the database connected, using DbConnection.GetSchema(). Unfortunately, the design of this is pretty shortsighted, in that it doesn't force one way to obtain meta data with the same resultsets onto EVERY ado.net provider in .net. So there are ado.net providers, which do implement GetSchema but the returned tables with meta-data are specific to their db. This means that it's hard to write db generic code for this.
On top of that, the more detailed meta-data can be db specific too. For example, oracle uses sequences and synonyms for everything. Access doesn't, sqlserver 2005 has synonyms but not sequences. Synonym retrieval for oracle works very different than it does for sqlserver 2005. etc. etc.
So it gets dirty pretty quickly. In the end, you'll end up with a lot of db specific code, wrapped in a driver per db.
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
.
- References:
- .NET database inspection API?
- From: Peter Duniho
- .NET database inspection API?
- Prev by Date: compare a list of integers
- Next by Date: Re: compare a list of integers
- Previous by thread: Re: .NET database inspection API?
- Next by thread: Re: .NET database inspection API?
- Index(es):
Relevant Pages
|