Trouble with DbConnection.GetSchema()

dotnet framework

Trouble with DbConnection.GetSchema()

Postby Sneil » Thu, 30 Mar 2006 00:11:14 GMT


I trying to get some schema info with help of string of code:
_conn.GetSchema("Tables", sa)
where _conn is type of DbConnection. So - sa must be string[] type. If
I define sa like this:
            string[] sa = new string[3];
            sa[0] = "master";
            sa[1] = null;
            sa[2] = "users";
all fine, I get row "master		dbo		users		BASE TABLE". This was SYSTEM
database. Now want the same but for my own MSSQL database with name
"TestBase". Such database definitely exist on the same server and
definitely has table "MyTbl2". So I re-define sa:
            string[] sa = new string[3];
            sa[0] = "TestBase";
            sa[1] = null;
            sa[2] = "MyTbl2";
and get... nothing. Just empty DataTable? :( What's wrong?

Similar Threads:

1.Does DbConnection.Dispose() call Close()?

2.ADO.Net DBConnection Visualizer

3.How to determine the data-provider type from a DbConnection ob

If you use ODBC is simple using reflection

Something in the line of this

IDbConnection DBConnection4Try= (IDbConnection) DBGenericConnection;
DBConnection4Try.ConnectionString=SN=bla bla

Type ConnectionType =DBConnection4Try.GetType();
PropertyInfo DriverPropertyInfo = ConnectionType.GetProperty("Driver");	
string Driver = (string) DriverPropertyInfo.GetValue(DBConnection4Try, null);

If Driver is "SQLSRV32.DLL" then the connection is to a SQL Server.
If is SORCL32.DLLthen the connection is to Oracle.

Piece of cake!

The generic connection object works as the same...
Be careful though when closing commands object and reader the close and 
explicit dispose order must be respected on ODBC. Otherwise it could happen 
that you are able to execute once and next time you could get errors.

"Herby" wrote:
> Thanks for that, thats given me an idea, i could use reflection too.>
> >

4.How to determine the data-provider type from a DbConnection object

Im trying to use prepared SQL and need to support both Oracle and SQL
server.  Im only dealing with the abstraction - i.e. DbConnection

When using DbParameters, for Oracle i have to use :myVar but for SQL
Server i have to use @myVar.  So the abstraction breaks down here.
Consequently i need to ask  "What database server are you?"  to then
prefix the correct parameter marker character( bring back the ? ).

Iv checked the DbConnection object and there do not seem to be any
appropriate methods, whereby the provider can override some method
which will return the identity.

How best can i determine the type of the DBMS i am currently connected

I do not want to burden the user with having to pass across some


5.stop dbconnection in InitializeComponent()

Is there any way to change the order code is generated in InitializeComponent()? 
Or to keep designer generated ADO.NET code from trying to connect?

If im dropping data adapters, connections, etc.. in the designer, as soon as the 
connection string is set any following code that references the connection 
object initiates the connection. I dont want any connection happening until I 
ask for it with a Fill() call. I dont want to have to wrap all my constructors 
with database exception handlers. Surely there is a way of having some control 
over this?


6. DbConnection Close Throwing Exception

7. DbConnection and Finalizer

8. DbConnection, DbDataReader and DbCommand

Return to dotnet framework


Who is online

Users browsing this forum: No registered users and 13 guest