Estoy realizando mi aplicacion cliente servidor, y el caso es que hice un state-less(por si no hay internet), en realidad una vez por dia al iniciar la aplicacion guardo un fichero xml de productos y otro de clientes (esto es solo un TPV), lo mismo con el ticket. Estos luego son enviados. Para lo mismo en el Source del .exe (ejecutable), primero creo el clientmodule que conecta al datasnap.
Trabajo con mysqlWorkbench y delphi. Pero tambien uso componenetes ZeosLib para traer datos, tengo entendido zeoslib accede directamente a la base de datos, es decir no tengo procedimientos en el server para cargar productos y clientes.
Entonces la aplciacion larga un cartel "trabajando sin conexion" y se abre el form sin problemas, amenos que el servicio de mysql (mysqld.exe) no este corriendo. entonces dice project1.exe ha detectado un problema y debe cerrarse.
En el source del exe:
Application.Initialize; Application.MainFormOnTaskbar := True; TStyleManager.TrySetStyle('Iceberg Classico'); Application.CreateForm(TClientModule1, ClientModule1); ScreenWidth:=screen.DesktopWidth; ScreenHeight:=screen.DesktopHeight; Application.CreateForm( TForm2, Form2); // Unit9.ScaleForm(Form2,ScreenWidth, ScreenHeight); Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm3, Form3); Application.CreateForm(TForm4, Form4); // Unit9.ScaleForm(Form4,ScreenWidth, ScreenHeight); Application.CreateForm(TForm5, Form5); Application.CreateForm(TCLIENTES, CLIENTES); Application.CreateForm(TForm7, Form7); Application.CreateForm(TForm8, Form8); Application.Run;
y en el "OnCreate" del clientmodule(trato de conectar sino cargo los ultimos xml):
procedure TClientModule1.DataModuleCreate(Sender: TObject); var admin:TIniFile; nombre,destino,hoy,hoycli:string; i,x:integer; ultimo:string; fecha:TDateTime; begin admin:=TIniFile.Create(ExtractFilePath(Application.ExeName )+ 'caja.ini'); try with ClientModule1.SQLConnection1 do begin Close; Params.Values['DriverName']:=admin.ReadString('admin','DriverName',''); Params.Values['HostName']:=admin.ReadString('admin','HostName',''); Params.Values['Port']:=admin.ReadString('admin','Port','211'); Connected:=True; end; with ClientModule1.ZConnection1 do begin Catalog := admin.ReadString('admintablas','Catalog',''); Database := admin.ReadString('admintablas','Database',''); HostName := admin.ReadString('admintablas','HostName',''); Password := admin.ReadString('admintablas','Password',''); Port := admin.ReadInteger('admintablas','Port',3306); Protocol := admin.ReadString('admintablas','Protocol',''); User := admin.ReadString('admintablas','User',''); Connected:=True; end; begin for i := 0 to ComponentCount -1 do begin if Components[i] is TZTable then TZTable(Components[i]).Active :=True; end; for i := 0 to ComponentCount -1 do begin if Components[i] is TZQuery then TZQuery(Components[i]).Active :=True; end; end; if (ClientModule1.SQLConnection1.Connected) then begin hoy:=ExtractFilePath(Application.ExeName)+ 'productos'+FormatDateTime('dd-mm-yyyy',Now) + '.xml'; hoycli:=ExtractFilePath(Application.ExeName)+ 'clientes'+FormatDateTime('dd-mm-yyyy',Now) + '.xml'; if FileExists(hoy) then begin ShowMessage('datos ya copiados'); else begin with ClientModule1.cdsprod do begin Active:=True; nombre:='productos'+FormatDateTime('dd-mm-yyyy',Now) + '.xml'; destino:=ExtractFilePath(Application.ExeName) + nombre; ClientModule1.cdsprod.SaveToFile(destino,dfXMLUTF8); end; end; if FileExists(hoycli) then begin ShowMessage('datos ya copiados'); else begin with cdsclientes do begin Active:=True; nombre:='clientes'+FormatDateTime('dd-mm-yyyy',Now) + '.xml'; destino:=ExtractFilePath(Application.ExeName) + nombre; ClientModule1.cdsclientes.SaveToFile(destino,dfXMLUTF8); end; end; end; except begin if FileExists(hoy) then begin cdsprod.LoadFromFile(hoy); ShowMessage('archivo de hoy'); else begin while not (FileExists(ultimo)) do begin ultimo:=ExtractFilePath(Application.ExeName)+ 'productos'+ FormatDateTime('dd-mm-yyyy',IncDay(Now,x)) + '.xml'; Dec(x); end; end; end; ShowMessage('trabajando sin conexion'); end; end;
Si es el servicio de mysql pueden ser los componentes zeos que de haber conexion los conecto?