Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

[RESOLVED] Need help with ADO.NET Entity Data Model

$
0
0
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?

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>