{"id":4102,"date":"2014-03-30T07:42:55","date_gmt":"2014-03-30T07:42:55","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/set-dynamic-connectionstring-entity-framework-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:42:55","modified_gmt":"2014-03-30T07:42:55","slug":"set-dynamic-connectionstring-entity-framework-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/set-dynamic-connectionstring-entity-framework-collection-of-common-programming-errors\/","title":{"rendered":"Set dynamic ConnectionString Entity Framework-Collection of common programming errors"},"content":{"rendered":"<p>I developed Asp.net application with Entity Framework and now i need to change entity connection string at run time.I tried following way.<\/p>\n<pre><code>public class DataLayer(){\n\nstatic DataLayer()\n{\n((EntityConnection)_dbEntity.Connection).StoreConnection.ConnectionString =    GetConnectionString();\n\n\/\/GetConnectonString() returns \"user id=xxxx;password=xxxx;database=xxxx;server=xxx.xxx.xx.xx\"\n}\n\nstatic DBContext _dbEntity = new DBContext();\n\/\/other codes\n}\n<\/code><\/pre>\n<p>And I checked following links too.Still I couldn&#8217;t change it.<\/p>\n<p>http:\/\/msdn.microsoft.com\/en-us\/library\/bb738533(v=vs.90).aspx<\/p>\n<p>http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/adodotnetentityframework\/thread\/8a89a728-6c8d-4734-98cb-11b196ba11fd<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I developed Asp.net application with Entity Framework and now i need to change entity connection string at run time.I tried following way. public class DataLayer(){ static DataLayer() { ((EntityConnection)_dbEntity.Connection).StoreConnection.ConnectionString = GetConnectionString(); \/\/GetConnectonString() returns &#8220;user id=xxxx;password=xxxx;database=xxxx;server=xxx.xxx.xx.xx&#8221; } static DBContext _dbEntity = new DBContext(); \/\/other codes } And I checked following links too.Still I couldn&#8217;t change it. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4102","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4102"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4102\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}