为什么在执行query查询时出现长时间等待呢? 同意 my_first(海浪) 的意见。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 跟记录多少可能没关吧因为并不是每次都会这样有时候很正常的源码 with qry_rwdmx do begin close; sql.Clear;{这是我附加的注释,希望别怪我名称取得太烂:)scph 生产批号khmc 客户名称zdr 制单人color 产品颜色hd 厚度bz 币制th 图号gg 规格ps 片数qg 切割qgrq 切割日期xm 洗磨xmrq 洗磨日期其他的都是名称然后日期 rg1 rg2是radiogrouprg1有"全部、交货日期、下单日期、生产批号rg2有"全部、规格、客户名称、图号} sql.Add('select scph, khmc, zdr, color, hd, bz, th, gg, ps,'); sql.add('qg, qgrq, xm, xmrq, gh, ghrq, jc, jcrq, yx, yxrq,'); sql.add('ys, ysrq, zk, zkrq from rwdmx'); case rg1.itemindex of//下面是条件 0: case rg2.ItemIndex of 0: sql.add('where fp<>'''''); 1: begin sql.add('where khmc like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 2: begin sql.add('where gg like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 3: begin sql.add('where th like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; end; 1: case rg2.ItemIndex of 0: begin sql.add('where xdrq>='''+edit1.text+''''); sql.add('and xdrq<='''+edit2.text+''''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 1: begin sql.add('where xdrq>='''+edit1.text+''''); sql.add('and xdrq<='''+edit2.text+''''); sql.add('and khmc like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 2: begin sql.add('where xdrq>='''+edit1.text+''''); sql.add('and xdrq<='''+edit2.text+''''); sql.add('and gg like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 3: begin sql.add('where xdrq>='''+edit1.text+''''); sql.add('and xdrq<='''+edit2.text+''''); sql.add('and th like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; end; 2: case rg2.ItemIndex of 0: begin sql.add('where jhrq>='''+edit1.text+''''); sql.add('and jhrq<='''+edit2.text+''''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 1: begin sql.add('where jhrq>='''+edit1.text+''''); sql.add('and jhrq<='''+edit2.text+''''); sql.add('and khmc like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 2: begin sql.add('where jhrq>='''+edit1.text+''''); sql.add('and jhrq<='''+edit2.text+''''); sql.add('and gg like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 3: begin sql.add('where jhrq>='''+edit1.text+''''); sql.add('and jhrq<='''+edit2.text+''''); sql.add('and th like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; end; 3: case rg2.ItemIndex of 0: begin sql.add('where scph>='''+edit1.text+''''); sql.add('and scph<='''+edit2.text+''''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 1: begin sql.add('where scph>='''+edit1.text+''''); sql.add('and scph<='''+edit2.text+''''); sql.add('and khmc like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 2: begin sql.add('where scph>='''+edit1.text+''''); sql.add('and scph<='''+edit2.text+''''); sql.add('and gg like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; 3: begin sql.add('where scph>='''+edit1.text+''''); sql.add('and scph<='''+edit2.text+''''); sql.add('and th like ''%'+edit3.text+'%'''); sql.add('and fp<>'''''); sql.add('order by scph'); end; end; end; //params[0].asstring:=''; if not prepared then prepare; try open; except execsql; end; end; 其实你先在SQL SERVER里运行,看一看它的速度如何?是什么结果这样你就可以把错误缩小 用SQL Server的查询分析器执行也是停住了所以我觉得是SQL Server 的问题但问题在哪呢? 不加条件执行查询,看看结果如何,然后依次加条件,看看是SQL SERVER自身的问题,还是其他问题! 我也很难随时进行测试的,因为这个问题并不是每次都这样等我要测试的时候就很正常,但说不定它不一会儿脾气又来了所以我暂时也不能试:(请你们再多给点方案,下次遇上时我再try,谢谢你们! 解决方法有:1、把查询语句放到线程中,若成功则置一个标志或直接显示到 DBGrid 中;2、检查网络的问题,还有在 TDatabase 中 KeepConnection 设为 True, 只要数据库一次连接成功后,以后打开表或查询会快一点;3、检查索引,索引的好坏会直接影响查询速度。 To kyee第一条放到线程是怎做呢? 把查询语句放到线程中打开type TOpenSQLThread = class(Thread) private FQuery: TQuery; protected procedure Execute; override; public constructor Create(AQuery: TQuery; AOnTerminate: TNotifyEvent); end;implementation{ TOpenSQLThread }constructor TOpenSQLThread.Create(AQuery: TQuery; AOnTerminate: TNotifyEvent);begin inherited Create(True); FQuery := AQuery; OnTerminate := AOnTerminate; // 查询结束时会激发的事件 Resume;end;procedure TOpenSQLThread.Execute;begin if not Terminated and Assigned(FQuery) then try FQuery.Open; except end;end; 谢谢kyee这两天都还没再出现问题,我将继续关注你们的答案,谢谢你们 To ywxweb是的,条件一样,但就是有时会出现这样的问题 To yiyijisi 记录数并不多,不到2万条To leo1111111 已建立了索引是采用C/S结构的,用户不多 你用的SQL语句需要按字段scph排序。所以建议你对字段scph建立索引。然后在SQL语句里直接使用索引,而不要使用order by scph。假设你对字段scph建立的索引名为Index_Scph,则SQL语句这样写:sql.Add('select scph, khmc, zdr, color, hd, bz, th, gg, ps,'); sql.add('qg, qgrq, xm, xmrq, gh, ghrq, jc, jcrq, yx, yxrq,'); sql.add('ys, ysrq, zk, zkrq from rwdmx (INDEX=Index_Scph)');.....注意,最后不要再使用 order by scph 。 你用ado吧,用异步方式,前台不受影响,后台查询 根据url提取页面内容 mxOutlookBarPro 里的 Header 怎么做成右键直接修改(象QQ那样修改)? 有沒有辦法取得鼠標當前所在的位置? 关于托盘的问题 窗口自适应问题 欢迎MIDAS高手进入…… 如何将数据库中的变量类型转成delphi的数据类型? 急救!在线等答案 请问如何让一个密码验证窗口作用在多个按钮中? 哪里有<delphi com深入编程>下载? 我被delphi征服了,用一天时间学会了三层构造,用一年时间也学不会发布它了 这样为什么会出错-保存BLOB字段(oracle) ,
因为并不是每次都会这样
有时候很正常的
源码
with qry_rwdmx do
begin
close;
sql.Clear;
{这是我附加的注释,希望别怪我名称取得太烂:)
scph 生产批号
khmc 客户名称
zdr 制单人
color 产品颜色
hd 厚度
bz 币制
th 图号
gg 规格
ps 片数
qg 切割
qgrq 切割日期
xm 洗磨
xmrq 洗磨日期
其他的都是名称然后日期
rg1 rg2是radiogroup
rg1有"全部、交货日期、下单日期、生产批号
rg2有"全部、规格、客户名称、图号}
sql.Add('select scph, khmc, zdr, color, hd, bz, th, gg, ps,');
sql.add('qg, qgrq, xm, xmrq, gh, ghrq, jc, jcrq, yx, yxrq,');
sql.add('ys, ysrq, zk, zkrq from rwdmx');
case rg1.itemindex of//下面是条件
0: case rg2.ItemIndex of
0: sql.add('where fp<>''''');
1: begin
sql.add('where khmc like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
2: begin
sql.add('where gg like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
3: begin
sql.add('where th like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
end;
1: case rg2.ItemIndex of
0: begin
sql.add('where xdrq>='''+edit1.text+'''');
sql.add('and xdrq<='''+edit2.text+'''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
1: begin
sql.add('where xdrq>='''+edit1.text+'''');
sql.add('and xdrq<='''+edit2.text+'''');
sql.add('and khmc like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
2: begin
sql.add('where xdrq>='''+edit1.text+'''');
sql.add('and xdrq<='''+edit2.text+'''');
sql.add('and gg like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
3: begin
sql.add('where xdrq>='''+edit1.text+'''');
sql.add('and xdrq<='''+edit2.text+'''');
sql.add('and th like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
end;
2: case rg2.ItemIndex of
0: begin
sql.add('where jhrq>='''+edit1.text+'''');
sql.add('and jhrq<='''+edit2.text+'''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
1: begin
sql.add('where jhrq>='''+edit1.text+'''');
sql.add('and jhrq<='''+edit2.text+'''');
sql.add('and khmc like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
2: begin
sql.add('where jhrq>='''+edit1.text+'''');
sql.add('and jhrq<='''+edit2.text+'''');
sql.add('and gg like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
3: begin
sql.add('where jhrq>='''+edit1.text+'''');
sql.add('and jhrq<='''+edit2.text+'''');
sql.add('and th like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
end;
3: case rg2.ItemIndex of
0: begin
sql.add('where scph>='''+edit1.text+'''');
sql.add('and scph<='''+edit2.text+'''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
1: begin
sql.add('where scph>='''+edit1.text+'''');
sql.add('and scph<='''+edit2.text+'''');
sql.add('and khmc like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
2: begin
sql.add('where scph>='''+edit1.text+'''');
sql.add('and scph<='''+edit2.text+'''');
sql.add('and gg like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
3: begin
sql.add('where scph>='''+edit1.text+'''');
sql.add('and scph<='''+edit2.text+'''');
sql.add('and th like ''%'+edit3.text+'%''');
sql.add('and fp<>''''');
sql.add('order by scph');
end;
end;
end;
//params[0].asstring:='';
if not prepared then prepare;
try
open;
except
execsql;
end;
end;
这样你就可以把错误缩小
所以我觉得是SQL Server 的问题
但问题在哪呢?
因为这个问题并不是每次都这样
等我要测试的时候就很正常,
但说不定它不一会儿脾气又来了
所以我暂时也不能试:(
请你们再多给点方案,
下次遇上时我再try,谢谢你们!
1、把查询语句放到线程中,若成功则置一个标志或直接显示到 DBGrid 中;
2、检查网络的问题,还有在 TDatabase 中 KeepConnection 设为 True, 只要数据库一次连接成功后,以后打开表或查询会快一点;
3、检查索引,索引的好坏会直接影响查询速度。
第一条放到线程是怎做呢?
type
TOpenSQLThread = class(Thread)
private
FQuery: TQuery;
protected
procedure Execute; override;
public
constructor Create(AQuery: TQuery; AOnTerminate: TNotifyEvent);
end;implementation{ TOpenSQLThread }constructor TOpenSQLThread.Create(AQuery: TQuery; AOnTerminate: TNotifyEvent);
begin
inherited Create(True); FQuery := AQuery;
OnTerminate := AOnTerminate; // 查询结束时会激发的事件 Resume;
end;procedure TOpenSQLThread.Execute;
begin
if not Terminated and Assigned(FQuery) then
try
FQuery.Open;
except
end;
end;
这两天都还没再出现问题,
我将继续关注你们的答案,
谢谢你们
是的,条件一样,但就是有时会出现这样的问题
记录数并不多,不到2万条
To leo1111111
已建立了索引
是采用C/S结构的,用户不多
在SQL语句里直接使用索引,而不要使用order by scph。假设你对字段scph建
立的索引名为Index_Scph,则SQL语句这样写:
sql.Add('select scph, khmc, zdr, color, hd, bz, th, gg, ps,');
sql.add('qg, qgrq, xm, xmrq, gh, ghrq, jc, jcrq, yx, yxrq,');
sql.add('ys, ysrq, zk, zkrq from rwdmx (INDEX=Index_Scph)');
.....
注意,最后不要再使用 order by scph 。