In order to use different connection strings for each database call you can override the CreateDataContext
method. You should do that in a partial class
of the target Domainservice
in order to keep the customization in case you regenerate the service in feature.
var clientId = WebOperationContext.Current.IncomingRequest.Headers[
var connStr = GetConnStrByClientId(clientId);
The above code shows how this could be done. You should create your data context manually and pass the connection string to its constructor. Now the question is how you know which connection string to be used for a given service request. Usually such problems are solved by passing additional information in the message header. The code sample above assumes that the Silverlight client application has added additional header to the message with name "ClientId
is a helpful article describing what should be done to implement this approach.
You should know that once created the data context is used during the entire lifetime of the DomanService instance. So if you control somehow the lifetime of the service classes you would need to override the DataContext property and implement your own logic when to create a new data context.
I would not suggest you to transport the connection string (even if it is encrypted) with each call. I would suggest you to implement token based authorization in your application. To do this when a given user is logged in the server should issue a token or the above sample this the clientId, then each call to the services should contain this token. The services should determine which connection string to use based on the passed token. This approach will work for the load operations and for the CUD operations.
I hope this helps. Should you have any questions do not hesitate to get back to us.
OpenAccess ORM is now Telerik Data Access
. For more information on the new names, please, check out the Telerik Product Map