事务出错the transaction isolation level must be dirty read for local databases
Query2.close;
Query2.Sql.clear;
Query2.SQL.Add('insert into userr (usernam,psw) values (:usname,:psww)');
Query2.ParamByName('usname').asstring:=ComboBox1.Text;
Query2.ParamByName('psww').asstring:=pssword;
//psword:= Query1.FieldValues['psw'];
//psw:= form1.UncrypKey(psw,'123456');
//psword.Text:=psw;
Database1.StartTransaction; //开始事务控制
try
Query2.ExecSQL; //开始插入记录
Database1.Commit; //提交事务
except
Query2.Free; //如果出错首先将Query Free掉
Database1.RollBack; //回退事务
raise; //重新引发异常,以通知用户
end;
Query2.free;
Query2.close;
Query2.Sql.clear;
Query2.SQL.Add('insert into userr (usernam,psw) values (:usname,:psww)');
Query2.ParamByName('usname').asstring:=ComboBox1.Text;
Query2.ParamByName('psww').asstring:=pssword;
//psword:= Query1.FieldValues['psw'];
//psw:= form1.UncrypKey(psw,'123456');
//psword.Text:=psw;
Database1.StartTransaction; //开始事务控制
try
Query2.ExecSQL; //开始插入记录
Database1.Commit; //提交事务
except
Query2.Free; //如果出错首先将Query Free掉
Database1.RollBack; //回退事务
raise; //重新引发异常,以通知用户
end;
Query2.free;
解决方案 »
- Delphi7中编译器错误?(非弱智问题)
- 大虾请教,用INDY做SMTP,如果有附件,就出错:mail data refused by AISP , rule 1900691
- 百分:EnumWindows来其它程序里面TStringGrid类型控件的句柄后怎么取里面的值?
- 小弟新开的一个网站www.matrixstudio.org
- 报表问题
- 小问题,帮忙解答
- 关于存储过程的问题
- 菜鸟的苦恼!!!请高手指教了!!!
- 关于修改CLASSES.PAS或是WINDOWS.PAS等几个底层的.PAS文件
- 全世界都不能回答的问题………………………………………………`…
- 如何实现主菜单栏跟标题栏在同一行
- 【立志贴】以后俺每天至少回复10贴技术贴,大家监督
var
Query2 : TQuery;
begin
Query2 := TQuery.Create(nil);
Query2.DatabaseName := 'db';
try
database1.StartTransaction;
try
with Query2 do
begin
close;
sql.Clear;
sql.Add('insert into userr (usernam,psw) values (:usname,:psww)');
ParamByName('usname').asstring:=edit1.Text;
ParamByName('psww').asstring:=edit2.text;
ExecSql;
end;
database1.Commit;
except
database1.Rollback;
raise;
{*
on e:exception do
begin
Database1.RollBack; //回退事务
showmessage(e.Message);
end;
*}
end;
finally
Query2.Free;
end;
end;
if Not Database1.InTransaction then
Database1.StartTransaction; //开始事务控制
Query2.close;
Query2.Sql.clear;
Query2.SQL.Add('insert into userr (usernam,psw) values (:usname,:psww)');
Query2.ParamByName('usname').asstring:=ComboBox1.Text;
Query2.ParamByName('psww').asstring:=pssword;
//psword:= Query1.FieldValues['psw'];
//psw:= form1.UncrypKey(psw,'123456');
//psword.Text:=psw;
Query2.ExecSQL; //开始插入记录
Database1.Commit; //提交事务
except
begin
Query2.Free; //如果出错首先将Query Free掉
Database1.RollBack; //回退事务
raise; //重新引发异常,以通知用户
end;
end;
Query2.free;
var
Query:TQuery;
begin
Query:=TQuery.Create(nil);
Query.DatabaseName:='Test';
try
database1.StartTransaction;
try
with Query do
begin
close;
sql.Clear;
sql.Add('insert into Logininfo (usernae,pwd) values (:username,:passwords)');
ParamByName('username').asstring:=edit1.Text;
ParamByName('passwords').asstring:=edit2.text;
ExecSql;
end;
database1.Commit;
except
database1.Rollback;
raise;
end;
finally
Query.Free;
end;
end;
..\db
不用事务,3楼的可以写入数据,用了事务就还是出上面的错误,说是数据库要用本地的数据库,怎么回事啊。
错误的提示是意思就是,让本地的数据库的脏读是第二级,就是让database1.TransIsolation赋值为tiDirtyRead ;