Kasrak
Kasrak

Reputation: 1561

Set the Entity Connection string in a different project

I want to place Entities and Database (here I used Sql Serve Ce) in a project, and use them in another project in the same solution.

I have problem setting the database location this way and the context is always null

Project One will have all the database , ConnectionString and entities

Project Two is the User project of the Entities defined in Project One

This is a Windows Forms Application And the name of the Entity Connection Name is dbEntitties

The database is in the root of the application folder

This was a sample connection string I had :

<add name="dbEntities"
 connectionString="metadata=res://*/dbModel.csdl|res://*/dbModel.ssdl|res://*/dbModel.msl;provider=System.Data.SqlServerCe.3.5;provider connection string=&quot;
 Data Source=|DataDirectory|\db.sdf;Password=xxxxxxx;Persist Security Info=True&quot;" providerName="System.Data.EntityClient" />

-- The project will work as it is expected if I place the database and entities in the same project, But placing them in a different project and referencing the that project wouldn't help, I got no errors but the context will remain null.

Any Ideas ?

Upvotes: 0

Views: 689

Answers (1)

jflood.net
jflood.net

Reputation: 2456

Okay, so from the comments above, we've established the reason is it's not picking up the config because you've placed it in the root along with the DB.

The config will only be picked up by the entry point. Placing it in the the Windows form should fix this issue.

Upvotes: 1

Related Questions