注册

【DmProvider】DmBulkCopy报错:Attempted to read or write protected memory.

DM_360065 2022/12/14 1267 2 已解决

为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM8(–03134283938-20221019-172201-20018)
【操作系统】:windows 10 64位
【CPU】:i5-10500
【问题描述】*:
【DmProvider】DmBulkCopy报错:System.AccessViolationException:“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”
环境变量已设置
参考以下问题均无解答:
https://eco.dameng.com/community/question/e1de0f0d2b3e7ca2304334f898c8fe34
https://eco.dameng.com/community/question/30efe4a9262682735d38dd8e1dfd2d32
版本:DmProvider.1.1.0.11058 (asp.net core 3.1 )
现象:
image.png
堆栈信息:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Dm.DmFldrDllCall.fldr_provider_get_err(IntPtr, Int32, Int32 ByRef, IntPtr ByRef) at Dm.DmFldrDllCall.fldr_provider_get_err(IntPtr, Int32, Int32 ByRef, IntPtr ByRef) at Dm.DmFldrDllCall.GetError(IntPtr, Int32 ByRef, System.String ByRef) at Dm.DmFldrDllCall.CheckTable(IntPtr, Int32) at Dm.DmFldr.Initilize(Dm.DmConnProperty, System.String, Dm.DmBulkCopyOptions, Int32, System.Data.DataTable) at Dm.DmBulkCopy.WriteToServer(System.Data.DataTable) at DmTest.Program.LaunchBulkCopy() at DmTest.Program.Main(System.String[])

示例代码:

internal static void LaunchBulkCopy() { const string tableName = "p_GlobalParam"; var entities = Enumerable.Range(1, 10).Select(x => new GlobalParam() { GlobalParamGUID = Guid.NewGuid(), SysCode = $"SysCode{x}", ParamCode = "ParamCode", ParamValue = $"ParamValue{x}", CreatedGUID = Guid.NewGuid(), CreatedName = "admin", CreatedTime = DateTime.Now, ModifiedGUID = Guid.NewGuid(), ModifiedName = "ModifiedName", ModifiedTime = DateTime.Now }); var dataTable = ToDataTable(entities.ToList()); using (var connection = new DmConnection(s_connectionString)) { connection.Open(); using (var bulkCopy = new DmBulkCopy(connection)) { //设置插入的目标表 bulkCopy.DestinationTableName = tableName; //DataTable列名与数据库列名的映射 for (int i = 0; i < dataTable.Columns.Count; i++) { bulkCopy.ColumnMappings.Add(dataTable.Columns[i].ColumnName, dataTable.Columns[i].ColumnName); } //写入数据库 bulkCopy.WriteToServer(dataTable); //System.AccessViolationException:“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” } } } private static DataTable ToDataTable<T>(IList<T> list) { Type elementType = typeof(T); DataTable dataTable = new DataTable(); //add a column to table for each public property on T foreach (var propInfo in elementType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { Type ColType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType; dataTable.Columns.Add(propInfo.Name, ColType); } //go through each property on T and add each value to the table foreach (T item in list) { DataRow row = dataTable.NewRow(); foreach (var propInfo in elementType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value; } dataTable.Rows.Add(row); } return dataTable; } [Serializable] public class GlobalParam { public Guid GlobalParamGUID { get; set; } public string SysCode { get; set; } public string ParamCode { get; set; } public string ParamValue { get; set; } public Guid CreatedGUID { get; set; } public string CreatedName { get; set; } public DateTime? CreatedTime { get; set; } public Guid ModifiedGUID { get; set; } public string ModifiedName { get; set; } public DateTime? ModifiedTime { get; set; } //public DateTime VERSIONNUMBER { get; set; } }

初始化表sql

CREATE TABLE IF NOT EXISTS "p_GlobalParam" ( "PARAMCODE" VARCHAR(128), "PARAMVALUE" VARCHAR(128), "SYSCODE" VARCHAR(128), "CREATEDGUID" CHAR(36), "CREATEDNAME" VARCHAR(128), "CREATEDTIME" TIMESTAMP(0), "GLOBALPARAMGUID" CHAR(36) NOT NULL, "MODIFIEDGUID" CHAR(36), "MODIFIEDNAME" VARCHAR(128), "MODIFIEDTIME" TIMESTAMP(0), "VERSIONNUMBER" TIMESTAMP(0) DEFAULT CURRENT_TIMESTAMP() NOT NULL) STORAGE(ON "MAIN", CLUSTERBTR);
回答 0
暂无回答
扫一扫
联系客服