locked
Question whether can dynamically assign DB connection (string) for ADO.net data services‏ RRS feed

  • Question

  • Hello,

    I am developing a single web (service) site that will be used by multiple clients.  Each client will have their own SQL Server DB instance, all in same model.  Is it possible to dynamically define/assign a connection string in ADO.net Data Services?  Please help.  Thanks.

    Monday, October 20, 2008 7:06 PM

Answers

  • Hi Junho,

    You could potentially override the CreateDataSource method in the generated service class to instantiate your data source object with your custom initialization strings per request.

     

    public class DataService<T> : IRequestHandler

    {

    ...

     

    // Summary:

    // Creates a data source of the template class that will be used by the data

    // service.

    //

    // Returns:

    // An instance of the data source.

    protected virtual T CreateDataSource();

     

    Thanks

    Waseem

     

    Monday, October 20, 2008 8:09 PM
    Answerer

All replies

  • Hi Junho,

    You could potentially override the CreateDataSource method in the generated service class to instantiate your data source object with your custom initialization strings per request.

     

    public class DataService<T> : IRequestHandler

    {

    ...

     

    // Summary:

    // Creates a data source of the template class that will be used by the data

    // service.

    //

    // Returns:

    // An instance of the data source.

    protected virtual T CreateDataSource();

     

    Thanks

    Waseem

     

    Monday, October 20, 2008 8:09 PM
    Answerer
  • Thanks Waseem.

     

    I wanted to use the existing Entity Data Model.  So, hinted from your recommendation, I found another approach by creating an own partial class of the generated context class, and define OnContextCreated with runtime generated Connection or ConnectionString.

     

    Junho.

     

    Tuesday, October 21, 2008 1:07 PM