OleDb数据提供程序给出错误E_NOINTERFACE

时间:2018-03-18 13:26:58

标签: c# powershell oledb

c#代码不起作用:

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();

例外:

  

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

     

в   System.Data.OleDb.OleDbConnectionInternal.ProcessResults(OleDbHResult   小时)

     

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

     

вSystem.Data.OleDb.OleDbConnection.GetOleDbSchemaTable(Guid架构,   对象[]限制)

     

вSystem.Data.OleDb.OleDbMetaDataFactory.PrepareCollection(String   collectionName,String [] restriction,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 [] restriction)

     

в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 \来源   代码\ SourceModules \的Ovation \开发\版本   2 \ SourceModule.Ovation \ ApiOvation.cs:строка58

     

SourceModule.Ovation.Program.Main(String [] args)в   E:\ TFS \ VM-TFS \ SAN \来源   代码\ SourceModules \的Ovation \开发\版本   2 \ SourceModule.Ovation \ Program.cs:строка20

有效的c#代码:

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代码:

$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()

限制输出包括collectionName“Tables”:

  

CollectionName RestrictionName RestrictionDefault RestrictionNumber
  -------------- --------------- ------------------ --- --------------
  列TABLE_CATALOG 1
  列TABLE_SCHEMA 2
  列TABLE_NAME 3
  列COLUMN_NAME 4
  表TABLE_CATALOG 1
  表TABLE_SCHEMA 2
  表TABLE_NAME 3
  表TABLE_TYPE 4

1 个答案:

答案 0 :(得分:0)

以下代码返回数据库中的表列表并保存到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();