OleDbProvider, db2, E_FAIL(0x80004005)
本文关键字:0x80004005 FAIL db2 OleDbProvider | 更新日期: 2023-09-27 17:55:46
在某些服务器中出现以下错误:
'IBMDADB2' failed with no error message available,
result code: E_FAIL(0x80004005).
at System.Data.OleDb.OleDbDataReader.ProcessResults(OleDbHResult hr)
at System.Data.OleDb.OleDbDataReader.BuildSchemaTableRowset(Object handle)
at System.Data.OleDb.OleDbDataReader.GenerateSchemaTable(
OleDbDataReader dataReader, Object handle, CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior
behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(
CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillSchemaInternal(DataSet dataset,
DataTable datatable, SchemaType schemaType, IDbCommand command,
String srcTable, CommandBehavior behavior) at
System.Data.Common.DbDataAdapter.FillSchema(DataSet dataSet,
SchemaType schemaType, IDbCommand command, String srcTable, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillSchema(DataSet dataSet,
SchemaType schemaType)
at BusinessLogiс.DB2.Database.GetData(String query,
String database, String host, String port, String login, String password)
获取数据方法:
public static DataTable GetData(string query, string database,
string host, string port, string login, string password)
{
OleDbConnection connection = null;
try
{
connection = Connection.GetConnection(database, host, port, login, password);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connection);
DataSet dataSet = new DataSet();
dataAdapter.FillSchema(dataSet, SchemaType.Mapped);
dataAdapter.Fill(dataSet);
return dataSet.Tables[0];
}
finally
{
Connection.CloseConnection(connection);
}
}
连接字符串:
connectionString = string.Format("Provider=IBMDADB2;
Database={0};Hostname={1};
Protocol=TCPIP;Port={2};
Uid ={3};Pwd={4};",
database, host, port, login, password);
不要忘记打开连接。
如果您只想查询和更新数据库,则实际上不需要 FillSchema。
您可以在 ADO.NET 中使用idb2connexion,idb2dataadapter,它更好
这里的例子
我删除了一行
dataAdapter.FillSchema(dataSet, SchemaType.Mapped);