Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to SQL - best way to switch between test & dev db

What is the simplest way to programmatically toggle back and forth between test and dev databases using the LINQ to SQL ORM?

like image 614
alchemical Avatar asked Jun 08 '09 18:06

alchemical


3 Answers

When newing up a DataContext, one of the overloads takes a connection string. I would therefore have a compiler switch something like:

 #if Debug
 string connectionString = ....
 #else
 string connectionString = ...
 #endif

 DbDataContext db = new DbDataContext(connectionString);
like image 106
BFree Avatar answered Sep 21 '22 11:09

BFree


Using a connection string in the web/app config. Have multiple configs for dev/test/prod. Each should have the appropriate connection string. Switch the config for each environment.

like image 43
tvanfosson Avatar answered Sep 23 '22 11:09

tvanfosson


using (MyDataContext dc = new MyDataContext(connectionString) )
{
  //do a unit of work.
}
like image 43
Amy B Avatar answered Sep 23 '22 11:09

Amy B