mORMot allows Access’s database to be accessed remotely
The TOLEDBJetConnectionProperties class is provided in mORMot to handle access to the Access mdb database, with its own thread pool.
Through the TSQLDBServerHttpApi class, we can put this TOleDBJetConnectionProperties
Publish to a remote external network to access the use. The server side should refer to the units SynDB, SynDBRemote, SynOleDB, and SynDBMidasVCL.
TSQLDBServerHttpApi uses the http.sys communication library of Microsoft IIS, which is stable and efficient.
code show as below:
unit FrmServerForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs,SynDB,SynDBRemote,SynOleDB,SynDBMidasVCL;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
DataBase:TSQLDBConnectionProperties;
DBServer: TSQLDBServerAbstract;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
DataBase := TOleDBJetConnectionProperties.Create('house.mdb;Jet OLEDB:Database Password=8888;','','','');
DBServer := TSQLDBServerHttpApi.Create(DataBase,'syndbremote','8092','admin','admin888',False);//将database连接到数据库house.mdb发布给远程客户端
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(DataBase);
FreeAndNil(DBServer);
end;
end.
As above, after a few simple code compile and run, the remote client can
remotely access the data on the processing server through the TSQLDBWinHTTPConnectionProperties class. When TSQLDBWinHTTPConnectionProperties creates a class instance, you need to specify the server ip, the database name to be accessed, the port, the username, and the password.
constructor TSQLDBWinHTTPConnectionProperties.Create(const aServerName, aDatabaseName, aUserID, aPassWord: RawUTF8);
By calling the TSynDBDataSet class of the SynDBMidasVCL unit, you can implement a call similar to the TAdoquery class. The client code is as follows:
unit FrmClientUnt;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids,
Data.DB, Vcl.ExtCtrls,SynDB,SynDBRemote,SynDBDataset,SynDBMidasVCL;
type
TForm2 = class(TForm)
Panel1: TPanel;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject);
var
Props:TSQLDBWinHTTPConnectionProperties;
cds:TSynDBDataSet;
begin
Props := TSQLDBWinHTTPConnectionProperties.Create('127.0.0.1:8092','syndbremote','admin','admin888');
cds := TSynDBDataSet.Create(Self);
cds.Connection := Props;//set TSynDBDataSet Connection
cds.CommandText :='select * from HouseInfo ';
cds.Open;
DataSource1.DataSet := cds;
end;
end.
Comment disabled