This is a migrated thread and some comments may be shown as answers.
same database on multiple servers
1 Answer 23 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ken
Top achievements
Rank 1
Ken asked on 30 Nov 2010, 09:37 PM

We have the same database on multiple servers. How can I programmatically via a web app change connection on the fly to a different server. All databases have the same name and schema.


Thanks

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 01 Dec 2010, 01:16 PM
Hello Ken,

You can use the constructor of the OpenAccessContext class which takes a connection parameter and pass a connection string or connection string name (if the connection string is itself present in the .config file). To switch to another server it is enough just to create a new context instance with the appropriate connection string. Here is an example:

string connectionOne = @"data source=.\sqlexpress;initial catalog=Northwind;integrated security=True";
string connectionTwo = @"data source=.\MSSQL;initial catalog=Northwind;integrated security=True";
 
//Work with database one
NorthwindEntityDiagrams context = new NorthwindEntityDiagrams(connectionOne);
Category category = new Category() { CategoryName = "CategoryOne" };
context.Add(category);
context.SaveChanges();
 
//Work with database two
context = new NorthwindEntityDiagrams(connectionTwo);
category = new Category() { CategoryName = "CategoryTwo" };
context.Add(category);
context.SaveChanges();

Hope that helps.

Best wishes,
Alexander
the Telerik team
Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Tags
Databases and Data Types
Asked by
Ken
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or