为提高效率,提问时请提供以下信息,问题描述清晰可优先响应。
【DM版本】:DM8
【操作系统】:win10专业版
【CPU】:
【问题描述】*:
CREATE TABLE IF NOT EXISTS tcomm_jyz_sty1e(
RecId int NOT NUIL,
RealValue varchar(20) DEFAULI NULL,
PRIMARY KEY (RecId)
);
delete from tcomm_jyz_sty1e;
INSERT INTO tcomm_jyz_sty1e (RecId,RealValue) VALUES (1,'单串');
INSERT INTO tcomm_jyz_sty1e (RecId,RealValue) VALUES (2,'双串');
CREATE TABLE IF NOT EXISTS tcomm_jyz_sty1e(
RecId int NOT NUIL,
RealValue varchar(20) DEFAULI NULL,
PRIMARY KEY (RecId)
);
/
delete from tcomm_jyz_sty1e;
INSERT INTO tcomm_jyz_sty1e (RecId,RealValue) VALUES (1,'单串');
INSERT INTO tcomm_jyz_sty1e (RecId,RealValue) VALUES (2,'双串');
达梦是不支持DDL和DML在一个事务中同时执行吗?
接口不支持,考虑以下方式:
public void ExecuteBatch(string sqlBatch)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
// 分割SQL语句(按分号加换行符分割)
var sqlStatements = sqlBatch.Split(
new[] { ";\r\n", ";\n" },
StringSplitOptions.RemoveEmptyEntries);
foreach (var sql in sqlStatements)
{
if (string.IsNullOrWhiteSpace(sql)) continue;
using (var command = new SqlCommand(sql, connection))
{
try
{
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine($"执行SQL失败: {sql}");
Console.WriteLine($"错误信息: {ex.Message}");
throw;
}
}
}
}
#
可能是因为数据库在默认事务模式下,执行DDL会隐式提交当前事务。此时若后续执行DML,会因事务状态异常导致错误。