This is a migrated thread and some comments may be shown as answers.

share connection string between orm project and data service project

1 Answer 54 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tony
Top achievements
Rank 1
Tony asked on 23 Nov 2012, 02:35 PM
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

1 Answer, 1 is accepted

Sort by
0
Hristo Marinov
Telerik team
answered on 28 Nov 2012, 10:02 AM
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.
Tags
Data Access Free Edition
Asked by
Tony
Top achievements
Rank 1
Answers by
Hristo Marinov
Telerik team
Share this question
or