Changing the RIA Services Connection String for Different Environments.

Changing the RIA Services Connection String for Different Environments.

by jbrooks 9. November 2011 07:24

On one project we keep our connection string as an AppSetting (See: HERE).  So that is what I use to build my RIA Services connection string to account for the differences between Dev, Test, QA and Prod.  You could also do the same with a regularly stored connection sting.  Here is how we did it:

public partial class MyDomainService
   {

       protected override MyEntities CreateObjectContext()
       {
           string ConnString = Common.cApp.AppSettings["DefaultConnection"];

           string seConn = ConfigurationManager.ConnectionStrings["MyEntities"].ToString();

           EntityConnectionStringBuilder ecsb = new EntityConnectionStringBuilder(seConn);
           ecsb.ProviderConnectionString = ConnString;

           EntityConnection ec = new EntityConnection(ecsb.ToString());

           ScheduleEntities ctx = new ScheduleEntities(ec);

           return ctx;

       }

   }

Tags:

Silverlight