Results 1 to 3 of 3

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

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Resolved [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?

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    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
  •  



Click Here to Expand Forum to Full Width