Frequently Asked Component Specific Questions
Options |
Display all FAQ items |
Displaying items 1 to 1 of 1, page 1 of 1
<< previous next >>
TMS RemoteDB
Setting SQL Server ApplicationName from client
Setting SQL Server ApplicationName from client
When using SQL Server at RemoteDB server side, you might want to make client to set ApplicationName parameter of server connection. You can achieve that by sending the parameter through a HTTP header “db-app-name", and using a middleware at server side to grab that value and set in connection. This approach can be used to set other server-side database connections from client side.
On server side:
threadvar ThreadApplicationName: string; procedure StartServer; var Server: THttpSysServer; Module: TRemoteDBModule; begin Server := THttpSysServer.Create; try Module := TRemoteDBModule.Create(''http://localhost:2001/tms/remotedb'', TDBConnectionFactory.Create( function: IDBConnection var Module: TConnectionModule; begin Module := TConnectionModule.Create(nil); // Use ThreadApplicationName to configure your connection if ThreadApplicationName <> '''' then Module.FDConnection.Params.Values[‘ApplicationName’] := ThreadApplicationName; Result := TFireDacConnectionAdapter.Create(Module.FDConnection1, Module); end ) ); Module.AddMiddleware(TAnonymousMiddleware.Create( procedure(C: THttpServerContext; Next: THttpServerProc) begin ThreadApplicationName := C.Request.Headers.Get(''db-app-name''); Next(C); ThreadApplicationName := ''''; end )); Server.AddModule(Module); Server.Start; WriteLn(''RemoteDB server running...''); ReadLn; finally Server.Free; end; end;
RemoteDBDatabase1.OnRequestSending := RequestSending; procedure TfmThreeTierAureliusRemoteDB.RequestSending(Sender: TObject; Req: THttpRequest); begin Req.Headers.SetValue(''db-app-name'', ''My Application''); end;