需要一个使用adoconection的例子来避免mysql服务器已经消失

时间:2016-09-07 03:35:53

标签: mysql delphi ado

我有一个使用远程数据库的桌面应用程序,遗憾的是我无法更改内存限制,当我使用本地数据库或LAN数据库时,我的应用程序是好的。但是当使用远程数据库时,我经常发现错误" mysql服务器已经消失了#39;我的假设是我没有很好地使用adoconnection。我做了ado.committrans和ado.begintrans,但我没有做ado.close或ado.free。 。我需要一个这样的例子......我使用什么功能以及我把它们放在哪里?每个事务包括显示给dbgrid?或者其他的东西.... 我的托管配置是:

> safe mode = Off (tidak dapat diubah)

memory_limit = 256M (MAXIMUM)

max_execution_time = 30 (MAXIMUM in seconds)

max_input_time = 60 (MAXIMUM in seconds)

post_max_size = 64M (MAXIMUM)

upload_max_filesize = 64M (MAXIMUM)

enable_dl = Off (tidak dapat diubah)

Stimultan connection: 25 connections/koneksi

**Time out without activity: 60 sec**

我想知道是否在我的项目中。我没有激活我的连接

这里是我的代码:

Procedure TForm1.show;
Begin
with query do begin
sql.clear;//menghapus query yang masih ada jika ada
sql.Text:='select * from daftar where tanggal = curdate() order by id asc';
open;//membuka query
end;
end;
  function AddLeadingZeroes(const aNumber, Length : integer) : string;
begin
   result := SysUtils.Format('%.*d', [Length, aNumber]) ;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a:string;
begin
a:=AddLeadingZeroes(strtoint(edit3.Text),4);
 edit3.text:=a;
 edit2.text:=AnsiUpperCase(edit2.text);
if (edit2.text='') or (edit3.text='')
  then
    begin
      showmessage('Nomor Medrek HARUS diisi terlebih dahulu');
      edit2.setfocus
    end
  else
    begin
      con.BeginTrans;
      query1.SQL.Clear;
      query1.SQL.text :='Select Nama from medrek where LETTER='+QuotedStr(edit2.text)+'AND ID='+QuotedStr(edit3.text)+';';
      Screen.Cursor:=crHourGlass;
      query1.open;
      If query1.RECORDCOUNT = 0
        Then
          begin
            ShowMessage('NOMOR MEDREK BELUM TERDAFTAR') ;
            edit1.Color := clMaroon;
            edit1.clear ;
            con.CommitTrans;
          end
        ELSE
          begin
            edit1.text := query1.FieldByName('Nama').AsString;
            edit1.Color := clYellow;
            query.Requery();
            con.CommitTrans;
          END;
    query1.close;
    Screen.Cursor:=crDefault;

    end

end;

procedure TForm1.Button2Click(Sender: TObject);

begin

if (edit1.text='') or (combobox1.text='') or (combobox2.text='') or (combobox3.text='')  or (combobox4.text='') then
    begin
    MessageDlg('DATA BELUM LENGKAP !',mtError, mbOKCancel, 0);
    end
      else
        begin
        Screen.Cursor:=crHourGlass;
            con.BeginTrans;
            with query do
            begin
                sql.Clear;
                SQL.Text:='INSERT INTO daftar (tanggal,NO_MEDREC, NAMA, lAMA, STATUS, KETERANGAN, POLI) VALUES ("'+formatdatetime('yyyy-mm-dd',today())+'","'+concat(Edit2.Text,'-',edit3.text)+'","'+Edit1.Text+'","'+combobox1.text+'","'+combobox3.text+'","'+combobox2.text+'","'+combobox4.text+'")';
                execsql;//untuk mengeksekusi perintah SQL
                Showmessage('Data berhasil disimpan');
                show;
            end;
        con.CommitTrans;
        Screen.Cursor:=crDefault;
        button1.Enabled:=false;
        button2.Enabled:=false;
          query1.close;
        end;
end;
procedure TForm1.ComboBox3Click(Sender: TObject);
begin
IF combobox3.text='UMUM'  THEN
  begin
   EDIT5.Color:=clBlack;
   EDIT5.CLEAR;
   EDIT5.ReadOnly := true
   END
   ELSE
   BEGIN
   EDIT5.Color:=clWHITE   ;
   EDIT5.ReadOnly := FALSE
   END

END;
procedure TForm1.Button3Click(Sender: TObject);
begin
con.connected:=true;
 with query do
            begin
                sql.Clear;
                SQL.Text:='Select * from daftar where tanggal = curdate()';
                execsql;//untuk mengeksekusi perintah SQL

                show;
                end;

button1.Enabled:=TRUE;
button2.Enabled:=TRUE;
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit5.Clear;
combobox1.ClearSelection;
combobox2.ClearSelection;
Combobox3.ClearSelection;
combobox4.ClearSelection;
edit2.SetFocus;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
con.connected:=true;
 with query do
            begin
                sql.Clear;
                SQL.Text:='Select * from daftar where tanggal = curdate()';
                execsql;//untuk mengeksekusi perintah SQL

                show;
                end;
Show;
end;

procedure TForm1.P2Click(Sender: TObject);
begin
FORM2.SHOWMODAL
end;

procedure TForm1.P1Click(Sender: TObject);
begin
form3.showmodal;
end;





procedure TForm1.CETAKClick(Sender: TObject);
begin
  form4.show;
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if DBGrid1.DataSource.DataSet.RecNo mod 2 =0 then
DBGrid1.Canvas.Brush.Color := clskyBlue; //pilih warnanya
DBGrid1.DefaultDrawColumnCell(rect, datacol, column, state);



if DataSource1.DataSet.RecNo > 0 then
begin
if Column.Title.Caption = 'No.' then
DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DataSource1.DataSet.RecNo));
end;
end;

procedure TForm1.CARIHISTORYPASIEN1Click(Sender: TObject);
begin
form5.show;
end;

End.

我将ado属性直接设置为其属性。不使用代码,,,, adoconnection的提供者。供应商= MSDASQL.1 和adoconnection.connected上的checked = true

谢谢..

1 个答案:

答案 0 :(得分:0)

  

MySQL服务器最常见的原因已经消失了   服务器超时并关闭连接。在这种情况下,你   通常会得到以下错误代码之一(你得到的是哪一个)   取决于操作系统。)

由于此原因,我收到了此错误

  

您在服务器端遇到超时和自动   禁用客户端中的重新连接(重新连接标志位于   MYSQL结构等于0)。

但是这个错误的完整原因在下面的链接中描述

http://dev.mysql.com/doc/refman/5.7/en/gone-away.html