现在客户端只要执行sql报一次错,数据库服务器进程就多一个
有个datasnap问题请教 现在客户端只要执行sql报一次错,数据库服务器进程就多一个
例如 在客户端执行 kill 1 因为是kill系统进程 肯定报错 但报一次错就多一个sqlserver连接进程,如何解决?
服务器端
function TServerMethods1.GetData(sql:string): TDataSet;
begin
try
SQLConnection1.Open;
SQLDataSet1.Close;
SQLDataSet1.CommandText:=sql;
SQLDataSet1.Open;
Result := SQLDataSet1
except
on E: Exception do
begin
SQLConnection1.Close;
SQLDataSet1.Close;
Result := nil;
end
end;
end;
procedure TServerMethods1.execsql(sql:string);
var
SQLQuery: TSQLQuery;
begin
try
try
SQLQuery := TSQLQuery.Create(nil);
SQLQuery.SQLConnection := SQLConnection1;
SQLQuery.CommandText :=sql;
SQLConnection1.open;
SQLQuery.ExecSQL;
except
on E: Exception do
begin
SQLConnection1.Close;
end
end;
finally
SQLConnection1.Close;
SQLQuery.Free;
end;
end;
=====================================
客户端
procedure TForm2.Button2Click(Sender: TObject);//正常
begin
try
DBGridEh1.DataSource := DataSource1;
SQLConnection1.Connected := True;
try
ClientDataSet1.Close;
SqlServerMethod1.Params.ParamByName('sql').Asstring := memo1.Text;
ClientDataSet1.Open;
except
on E: Exception do
begin
SQLConnection1.Connected := False ;
showmessage('错误');
end
end
finally
SQLConnection1.Connected := False
end;
end;