views:

214

answers:

1

With DataSnap 2009 i seems to be possible to use a remote database connection in the client datamodule, using a TDSProviderConection and an associated TSQLConnection. The client side is easy to set up, I drop a TSQLConnection on the form and link it to the TDSProviderConnection component.

But what are the steps in the remote datamodule on the server side to provide the 'real' SQLConnection to the client? I have a server module which inherits from TDSServerModule, a TDSTCPServerTransport, a TDSServer and a TDSServerClass component. How do I link these to a server side TSQLConnection?

+3  A: 

In fact the easiest way to access the serverside database connection from DataSnap 2009 client is to use just a TSQLConnection component. Set its "Driver" property to "DataSnap" and in the "ServerConnection" subproperty specify a server method that returns a "TDBXConnection" reference. You can manually add such a server method to your remote data module. It is easier to use a build-in "DSAdmin.GetConnection" server method and just specify then name of the DBExpress connection as it appears in Data Explorer on the serverside or is specified in DBXConnection.ini file. The gotcha is to use double quotes around connection name. For example if you have an InterBase connection named "IBEMPLOYEE" in Data Explorer, just enter into "ServerConnection" the following string:

DSAdmin.GetConnection("IBEMPLOYEE")

and set "Connected" property to "true".

In this scenario you do not need to anything special on the DataSnap server. In fact you do not even need a server module as you are using a built-in one.

HIH

Pawel

Paweł Głowacki
Will the server side TSQLConnection properties override the settings of the client side TSQLConnection? If yes, how would I pass parameters to the server to configure the connection, for example if the client needs to set some session-specific things (like the user name) in the database configuration before the server side TSQLConnection is opened?
mjustin
I guess not. The server would not override the client side connection. The solution would be to create a server method that accepts all the necessary parameters for the server side connection, like passing username/password.
Paweł Głowacki