share connection string between orm project and data service project

Thread is closed for posting
2 posts, 0 answers
  1. Tony
    Tony avatar
    7 posts
    Member since:
    Nov 2012

    Posted 23 Nov 2012 Link to this post

    I have a ORM project with only entities model in it. The connection string is stored in app.config of the project called MyConnectionString.

    I then setup an empty WCF service project for the data service. Right clicked on the entities model in ORM project to "Add OpenAccess Service" into the WCF Service project. In the WCF service project the connection string is stored in its web.config, also called MyConnectionString.

    Now I have 2 connection strings with same name in both projects. If I want to point the service to a different database I have to change the connectionstring details in both places before publish. This is a major restriction for me.

    Is there a way I can get the ORM project to consume the same connectionstring in the web.config of the WCF service project, so that when I deploy the project I only need to change connectionstring details in one place, and without having to republish.

    thanks in advance
  2. Hristo Marinov
    Hristo Marinov avatar
    13 posts

    Posted 28 Nov 2012 Link to this post

    Hello Tony,

    In your scenario, the connection string for the Domain Model is taken from the web.config file of the WCF Service project. When you initialize the entities in the service, OpenAccess will always refer to the web project configuration rather than the model app.config.

    This means that if you change the connection string only in the web.config file, the WCF service will work correctly.

    There are two things to bare in mind. First, when you change the connection string, it has to be pointing to a database with the same schema. Second, in case another project refers to the Domain Model project, it will use its own configuration (app.config or web.config). Also, if the model project can be used by itself (console application, windows application, etc.), the connection string will be loaded from the app.config.

    For more information, you can refer to this documentation article.

    If you have any other issues, please feel free to contact us.

    All the best,
    Hristo Marinov
    the Telerik team
    Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Back to Top