尝试使用 Oracle Data Access ODP.NET 11.2 执行 ExecuteReader() 时出现 InvalidOperationException
这是我第一次与 Oracle 合作,因为我们都讨厌与国外的东西一起工作,而你多年来一直在使用特定的模型,尽管这是我们的工作,我们必须做到这一点。
现在我已经安装了 Oracle 11 g 并复制并引用了 Oracle.DataAccess.dll 创建了一个方法,在该方法中打开连接并尝试从服务器上创建的视图中检索一些对象。
方法:
public BindingList<HeaderReceiver> GetHeaderReceivers()
{
try
{
using (OracleConnection db = new OracleConnection(BaseDataAccess.ConnString))
{
string cmdText = "select * from p_customer t";
BindingList<HeaderReceiver> headerReceivers = new BindingList<HeaderReceiver>();
OracleCommand cmd = new OracleCommand(cmdText) { CommandType = CommandType.Text };
db.Open();
OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); <--- Error Occurs HERE!!!
while (reader.Read())
headerReceivers.Add(HeaderReceiver.GetInstance(reader));
CustBranchRepository rep = new CustBranchRepository();
headerReceivers.ForEach(p => p.DetailsBranch = rep.GetDetailReceivers(p.Id));
reader.Close();
db.Close();
return headerReceivers;
}
}
catch (Exception ex)
{
ExporterLogger.Log(ex);
return null;
}
}
现在,当 ExecuteReader() 提交时,我收到此 InvalidOperationException。
Operation is not valid due to the current state of the object.
StackTrace:
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(CommandBehavior behavior)
at Exporter.Boss.DataAccess.CustomerRepository.GetHeaderReceivers() in ...Exporter\Exporter.Boss.DataAccess\CustomerRepository.cs:line 25
任何想法和帮助...
谢谢!
It's the first time I HAVE to work with Oracle, and as we all hate to work with foreign stuff while you are working with a specific model some years, although this is our job and we have to make it.
Now i have installed the Oracle 11 g and copied and referenced the Oracle.DataAccess.dll created a method where opens a connection and tries to retrieve some objects from a view that has been created on the server.
Method:
public BindingList<HeaderReceiver> GetHeaderReceivers()
{
try
{
using (OracleConnection db = new OracleConnection(BaseDataAccess.ConnString))
{
string cmdText = "select * from p_customer t";
BindingList<HeaderReceiver> headerReceivers = new BindingList<HeaderReceiver>();
OracleCommand cmd = new OracleCommand(cmdText) { CommandType = CommandType.Text };
db.Open();
OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); <--- Error Occurs HERE!!!
while (reader.Read())
headerReceivers.Add(HeaderReceiver.GetInstance(reader));
CustBranchRepository rep = new CustBranchRepository();
headerReceivers.ForEach(p => p.DetailsBranch = rep.GetDetailReceivers(p.Id));
reader.Close();
db.Close();
return headerReceivers;
}
}
catch (Exception ex)
{
ExporterLogger.Log(ex);
return null;
}
}
Now when ExecuteReader() commits I get this InvalidOperationException.
Operation is not valid due to the current state of the object.
The StackTrace:
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(CommandBehavior behavior)
at Exporter.Boss.DataAccess.CustomerRepository.GetHeaderReceivers() in ...Exporter\Exporter.Boss.DataAccess\CustomerRepository.cs:line 25
Any thoughts and help...
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您缺少命令对象上的连接......
It looks like you're missing the connection on the command object...