0

I've been dabbling a bit recently with Entity Framework 5.0. The application that I'm writing currently uses a database on a development/testing server. Once the application is complete, though, it should be able to connect to multiple instances of the database on different servers. Basically, the same database will be on several different serves. They have the exact same layout, just different information contained within.

The user should be able to select which server they will access from a dropdown on the form. Using their choice, the program will connect to the correct database server.

So, I'm wondering what caveats I should keep in mind while attempting this? Is it feasible/doable to let the program choose a different database/server based on user input? Will I have any special considerations because of using EF 5.0?

2
  • Database or Code first? Commented Aug 4, 2014 at 17:24
  • Database first. The model was generated from an existing database. The layout/structure is exactly the same on each server. Commented Aug 4, 2014 at 17:27

1 Answer 1

1

So long as you can guarantee the database layout is identical - and having non-sync'd data is intended, you should have no problems with this.

I believe you will have to add a new constructor for your context using a partial class that will accept the connection string.

public partial class MyContext
{
    public MyContext(string connectionstring) : base(connectionstring){}
}

And that should do it.

Make sure to use an Entity Framework friendly connection string. See http://msdn.microsoft.com/en-us/library/vstudio/cc716756(v=vs.100).aspx

Using different connection strings is frequently done to target different development / production databases. I've never run across your usage - but it should function just the same.

Sign up to request clarification or add additional context in comments.

1 Comment

The issue with this is that database first dbcontext does not use an standard SQL connection string. As long as you provide an Entity Framework connection string then this works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.