0
votes

c# code that doesn't work:

string connectionString = "Provider=OvHOleDbProv.OvHOleDbProv.1;Persist Security Info=True;User ID=user;Password=password;Data Source=192.168.7.96;Location=\"\";Mode=ReadWrite;Extended Properties=\"\";";
OleDbConnection _connection = new OleDbConnection(connectionString);
_connection.Open();
DataTable schema = _connection.GetSchema("Tables"); // Exception see below
_connection.Close();

Exception:

System.Data.OleDb.OleDbException (0x80004002): Сбой "OvHOleDbProv.OvHOleDbProv.1" без сообщения об ошибке, код результата: E_NOINTERFACE(0x80004002).

в System.Data.OleDb.OleDbConnectionInternal.ProcessResults(OleDbHResult hr)

в System.Data.OleDb.OleDbConnectionInternal.GetSchemaRowset(Guid schema, Object[] restrictions)

в System.Data.OleDb.OleDbConnection.GetOleDbSchemaTable(Guid schema, Object[] restrictions)

в System.Data.OleDb.OleDbMetaDataFactory.PrepareCollection(String collectionName, String[] restrictions, DbConnection connection)

в System.Data.ProviderBase.DbMetaDataFactory.GetSchema(DbConnection connection, String collectionName, String[] restrictions)

в System.Data.ProviderBase.DbConnectionInternal.GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, String collectionName, String[] restrictions)

в System.Data.OleDb.OleDbConnection.GetSchema(String collectionName, String[] restrictionValues)

в System.Data.OleDb.OleDbConnection.GetSchema(String collectionName)

в SourceModule.Ovation.ApiOvation.ExportSignals(String filename) в E:\tfs\vm-tfs\SAn\Source code\SourceModules\Ovation\Development\Version 2\SourceModule.Ovation\ApiOvation.cs:строка 58

в SourceModule.Ovation.Program.Main(String[] args) в E:\tfs\vm-tfs\SAn\Source code\SourceModules\Ovation\Development\Version 2\SourceModule.Ovation\Program.cs:строка 20

c# code that works:

string connectionString = "Provider=OvHOleDbProv.OvHOleDbProv.1;Persist Security Info=True;User ID=user;Password=password;Data Source=192.168.7.96;Location=\"\";Mode=ReadWrite;Extended Properties=\"\";";
OleDbConnection _connection = new OleDbConnection(connectionString);
_connection.Open();
DataTable schema = _connection.GetSchema("Restrictions");
_connection.Close();

PS code that works for both cases:

$connectionString='Provider=OvHOleDbProv.OvHOleDbProv.1;Persist Security Info=True;User ID=user;Password=password;Data Source=192.168.7.96;Location="";Mode=ReadWrite;Extended Properties="";' 
$oCon = New-Object System.Data.OleDb.OleDbConnection $connectionString 
$oCon.Open() 
$schema = New-Object System.Data.DataTable
$schema = $oCon.GetSchema("Tables") 
$schema
$schema = $oCon.GetSchema("Restrictions")
$schema
$oCon.Close()

Restrictions output include collectionName "Tables":

CollectionName RestrictionName RestrictionDefault RestrictionNumber
-------------- --------------- ------------------ -----------------
Columns TABLE_CATALOG 1
Columns TABLE_SCHEMA 2
Columns TABLE_NAME 3
Columns COLUMN_NAME 4
Tables TABLE_CATALOG 1
Tables TABLE_SCHEMA 2
Tables TABLE_NAME 3
Tables TABLE_TYPE 4

1
@FrancescoB. , msdn_restrictions. In Tables list of available tables in Database. - Ageev Dmitry
@FrancescoB., I can add link to files with result of GetSchema("Tables") and GetSchema("Restrictions") in PS. - Ageev Dmitry
@FrancescoB., I tried to use this syntax, but it also leads to an error. I can repeat it, but you need to wait a bit. The version of the oledb driver is old, and perhaps not complete. Because of this, there are many problems. - Ageev Dmitry
@FrancescoB., thank you. CLRVersion 4.0.30319. I'll try to build my application for this version. - Ageev Dmitry
@FrancescoB., thank you very much for trying to find a solution. I found another way to solve. - Ageev Dmitry

1 Answers

0
votes

The following code returns a list of tables in the database and save to xml:

string connectionString = "Provider=OvHOleDbProv.OvHOleDbProv.1;Persist Security Info=True;User ID=user;Password=password;Data Source=192.168.7.96;Location=\"\";Mode=ReadWrite;Extended Properties=\"\";";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();
OleDbCommand command = new OleDbCommand() { Connection = connection, CommandText = "select TABLE_NAME from SYSTABLES where TABLE_TYPE='TABLE'" };
OleDbDataReader datareader = command.ExecuteReader();
DataTable data = new DataTable();
data.Load(datareader);
data.TableName = "SYSTABLES"; // necessary for writing to xml
data.WriteXml("tables.xml");
connection.Close();