今天在使用另外一个数据库通过DBLINK 链路进来的一张表时,抛出“ORA-02041: 客户数据库未开始一个事务处理”异常,但是简单的BeginTransaction好像并不能解决问题,苦翻了一通资料,又上网转了半天,结果没发现什么有价值的方法。下面列出一个可以利用ADO.NET读取链路表数据的函数,关于更新操作还没办法,留在这里就当是时刻提醒自己还有一个问题要解决吧。
OracleCommand command = new OracleCommand();
oracleConnection1.Open();
command.Connection = oracleConnection1;
command.Transaction = oracleConnection1.BeginTransaction(IsolationLevel.ReadCommitted);
//这句很关键
command.CommandText = "SET TRANSACTION READ ONLY";
OracleDataReader oraDr = command.ExecuteReader();
command.CommandText = "select * from GISAG02_SYN";
OracleDataAdapter oda = new OracleDataAdapter();
DataTable dtTable = new DataTable();
oda.SelectCommand = command;
oda.Fill(dtTable);
DBGrid1.DataSource = dtTable;
oracleConnection1.Open();
command.Connection = oracleConnection1;
command.Transaction = oracleConnection1.BeginTransaction(IsolationLevel.ReadCommitted);
//这句很关键
command.CommandText = "SET TRANSACTION READ ONLY";
OracleDataReader oraDr = command.ExecuteReader();
command.CommandText = "select * from GISAG02_SYN";
OracleDataAdapter oda = new OracleDataAdapter();
DataTable dtTable = new DataTable();
oda.SelectCommand = command;
oda.Fill(dtTable);
DBGrid1.DataSource = dtTable;