Winforms using Entity Framework with edmx; retrieve connexion string from registry

188 Views Asked by At

I am working on a Winforms application using Entity Framework 6 with an .EDMX diagram which generates the context and entities for me.

The connection string is stored in app.config by default.

I want to change the source of my connection string, and I want to retrieve it from the Windows registry.

How can I do that?

1

There are 1 best solutions below

0
On

Try this:

MyEntities ctx = new MyEntities();
ctx.Database.Connection.ConnectionString = "...";

You can read connection string data from registry and assgin it to "ConnectionString" property.

It works but you have to assgin connection string everytime a new context object is created and also do not remove the original connection string from the app.config file.