I develop a product with a custom database configuration. I use ADO.NET with System.Data.Odbc.OdbcConnection for it. To make some differences between the databases is there a simple solution to detect the current DBMS of a connection.
+1
A:
connection.Database would work or you can execute
select db_name()
to expand on connection.Database
connection.Open();
Console.WriteLine("ServerVersion: " + connection.ServerVersion
+ "\nDatabase: " + connection.Database);
connection.ChangeDatabase("master");
Console.WriteLine("ServerVersion: " + connection.ServerVersion
+ "\nDatabase: " + connection.Database);
Console.ReadLine();
SQLMenace
2009-01-28 17:49:07
+2
A:
I think that the OdbcConnection.Driver property may be more appropriate in the OP's context, since ServerVersion should return only the version number.
The Driver property will return the name of the DLL, such as "Sqlsrv32.dll" in case of SQL server. Then the OP can apply case based logic.
Cerebrus
2009-01-28 18:33:58
I understood it as he wants the default database name
SQLMenace
2009-01-28 18:41:12
A:
I found the follow solution self:
DataTable td = conn.GetSchema(DbMetaDataCollectionNames.DataSourceInformation);
DataRow info = td.Rows[0];
String name = info[DbMetaDataColumnNames.DataSourceProductName];
For example this returns Microsoft SQL Server and is driver independent.
Horcrux7
2009-01-30 18:54:55