我想将数据从Timesten DB加载到数据表,但我遇到了错误这是我的代码
脚本:
create or replace FUNCTION APITT_tbl_request(prefix_db IN VARCHAR2) RETURN SYS_REFCURSOR AS
res SYS_REFCURSOR;
BEGIN
OPEN res FOR SELECT * FROM APITT_tbl_request_in;
RETURN res;
END;
C#代码
conn = new OracleConnection(conf.GetAPIDatabaseConnectionString());
conn.Open();
OracleTransaction tran = conn.BeginTransaction(IsolationLevel.ReadCommitted);
OracleCommand command = new OracleCommand();
DataTable dt = new DataTable();
command = new OracleCommand(@"BEGIN :RETURNCURSOR := APITT_tbl_request(:prefix_db); END;");
command.CommandType = CommandType.Text;
command.Parameters.Add("RETURNCURSOR", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
command.Parameters.Add("prefix_db", OracleDbType.Varchar2, ParameterDirection.Input).Value = prefix_db;
OracleDataAdapter da = new OracleDataAdapter(command);
da.Fill(dt);
数据填充错误(dt);
{System.InvalidOperationException: Operation is not valid due to the current state of the object. at Oracle.DataAccess.Client.OracleCommand.ExecuteReader
您尚未设置命令使用的连接。
使用ODP.NET,可以同时打开多个连接。如果您没有指定命令应该使用哪个连接,ODP.NET应该如何知道?
要么添加行
command.Connection = conn;
或更换线路
OracleCommand command = new OracleCommand();
带有
OracleCommand command = conn.CreateCommand();