how to switch DB connection in EF RRS feed

  • Question

  • Hi, I have a WPF application based on EF 6. currently, it runs database first, and it runs on local. I need setup two remote servers, how can I dynamically switch the connections?
    Friday, February 17, 2017 2:29 PM


  • Hi sdnd2000,

    >>how can I dynamically switch the connections?

    You could change the connection string via configuration file (such as web.config, app.config).

        <add name="DemoEntities" connectionString="metadata=res://*/DemoContext.csdl|res://*/DemoContext.ssdl|res://*/DemoContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;yourconnectionstring&quot;" providerName="System.Data.EntityClient" />

    In addition, you could also change your connection strings programatically. please refer to: Example 16.2. Programmatically modifying an EntityConnectionString.

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, February 20, 2017 1:55 AM