[RESOLVED] Need help with ADO.NET Entity Data Model
I created an Entity Data Model and got a WCF client-server app up and running. Now we're ready to test deploy, and the server should connect to a different database than it did during testing. I cannot find a way to change the database that the model hits.
I access the database in the following manner:
Code:
List<PolicyBDO> policyBDOs = null;
using (var PolicyEntities = new PolicyEntities())
{
DateTime now = DateTime.Now;
var policy = (from p in PolicyEntities.Table1 where p.Num.StartsWith(NumVal) && p.Type == TypeVal orderby p.Num,p.BeginDate select p);
}
If I run it as is, it uses the original database I used when creating the EDM. I CAN change the database at run time by changing the code as follows:
Code:
List<PolicyBDO> policyBDOs = null;
using (var PolicyEntities = new PolicyEntities())
{
String conn = PolicyEntities.Database.Connection.ConnectionString;
PolicyEntities.Database.Connection.ConnectionString = conn.Replace("OldServer", "NewServer");
DateTime now = DateTime.Now;
var policy = (from p in PolicyEntities.Table1 where p.Num.StartsWith(NumVal) && p.Type == TypeVal orderby p.Num,p.BeginDate select p);
}
So I have a workaround, but I shouldn't NEED to do it that way. How can I change the database connection within the Entity Data Model itself, so that it automatically connects to the new database?
Re: Need help with ADO.NET Entity Data Model
Entity Framework stores the connection string in your web.config. There should be a value in there and you can change the server url/instance as well as the username and password.
Re: Need help with ADO.NET Entity Data Model
I got iit working for the production server... thanks.