【DM版本】:DM8(–03134283938-20221019-172201-20018)
【操作系统】:windows 10 64位
【CPU】:i5-10500
【问题描述】*:
【DmProvider】DmConnection连接复用第二次查询报错。(System.ArgumentException:“Source array was not long enough. Check the source index, length, and the array’s lower bounds. ”)
版本:DmProvider.1.1.0.11058
现象:
示例代码:
internal static void LaunchQueryWithConnectionScope()
{
var sql = @"SELECT 'jack' name,12 age FROM DUAL";
using (var connection = new DmConnection(s_connectionString))
{
DmCommand cmd = new DmCommand();
cmd.Connection = connection;
cmd.CommandText = sql;
// 第一次查询
connection.Open();
var reader1 = cmd.ExecuteReader();
Read(reader1); // 读取并释放datareader
connection.Close();
// 第二次查询
connection.Open();
var reader2 = cmd.ExecuteReader();
Read(reader2); // 读取并释放datareader ,此处报错 System.ArgumentException:“Source array was not long enough. Check the source index, length, and the array's lower bounds. ”
connection.Close();
}
}
private static void Read(IDataReader dataReader)
{
using (dataReader)
{
while (dataReader.Read())
{
for (int i = 0; i < dataReader.FieldCount; i++)
{
string name = dataReader.GetName(i);
object val = dataReader.GetValue(i);
}
}
}
}
堆栈信息:
System.ArgumentException
HResult=0x80070057
Message=Source array was not long enough. Check the source index, length, and the array's lower bounds.
Source=System.Private.CoreLib
StackTrace:
在 System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
在 Dm.DmResultSetCache.GetBytes(Int16 columnNo, Byte[]& val_buf)
在 Dm.DmDataReader.GetByteArrayValue(Int32 columnIndex, Byte[]& value)
在 Dm.DmDataReader.do_GetValue(Int32 i)
在 Dm.DmDataReader.GetValue(Int32 i)
在 DmTest.Program.Read(IDataReader dataReader) 在 C:\workspace\repository\DmTest\DmTest\Program.cs 中: 第 265 行
在 DmTest.Program.LaunchQueryWithConnectionScope() 在 C:\workspace\repository\DmTest\DmTest\Program.cs 中: 第 209 行
在 DmTest.Program.Main(String[] args) 在 C:\workspace\repository\DmTest\DmTest\Program.cs 中: 第 26 行
开启事务可以
在连接字符串中开启连接池 conn_pooling=True 可以解决此问题。
该问题,大家注意更新到最新的Dmprovider即可。
同样的问题在EFCore中也存在。