-
Jun 11th, 2013, 02:24 PM
#1
Thread Starter
Hyperactive Member
[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?
-
Jun 11th, 2013, 04:35 PM
#2
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.
-
Jun 12th, 2013, 08:57 AM
#3
Thread Starter
Hyperactive Member
Re: Need help with ADO.NET Entity Data Model
I got iit working for the production server... thanks.
Last edited by HongKongCV; Jun 12th, 2013 at 09:01 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|