Closed
Description
This code succeeds in raw ADO.net Executereader(), but fails in dapper Executereader().
IDataReader.Read() throws a System.InvalidOperationException exception with the message:
Invalid attempt of read when the reader is closed.
using System;
using System.Data;
using Dapper;
using FirebirdSql.Data.FirebirdClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var cs = @"initial catalog=localhost:database;user id=SYSDBA;password=masterkey";
var sql = @"select count(*) from user";
var con = new FbConnection(cs);
con.Open();
// raw ADO.net
var sqlCmd = new FbCommand(sql, con);
IDataReader reader1 = sqlCmd.ExecuteReader();
while (reader1.Read())
{
Console.WriteLine(reader1[0].ToString()); // output is 10
}
// dapper
var reader2 = con.ExecuteReader(sql);
while (reader2.Read()) // System.InvalidOperationException. "Invalid attempt of read when the reader is closed."
{
Console.WriteLine(reader2[0].ToString());
}
Console.Read();
}
}
}
Stack trace:
System.InvalidOperationException was unhandled by user code.
HResult=-2146233079
Message=Invalid attempt of read when the reader is closed.
Source=FirebirdSql.Data.FirebirdClient
StackTrace:
at FirebirdSql.Data.FirebirdClient.FbDataReader.CheckState()
at FirebirdSql.Data.FirebirdClient.FbDataReader.Read()
at ConsoleApplication2.Program.Main(String[] args) at c:\Users\aoki\Desktop\ConsoleApplication2\ConsoleApplication2\Program.cs:行 33
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Metadata
Metadata
Assignees
Labels
No labels