In a C# 2010 application, I used linq to sql. I did this so I could use the visual designer to drag the sql server 2008 r2 tables onto the designer suraface. This works fine if your development database is the same database where the production database is located.
However my problem is that I now need to move the code from my development database to a user acceptance database. The problem is the database connections are now hard coded into the applications.
Thus my questions are the following:
1. What can I do in the code so the database name is not hard coded? Do I need to modify a constuctor?
2. I would like the database connection information to be obtained from the app. config file.
Thus can you show me code on how to accomplish my goals?
Loading
Felipe RamosPosted Oct 28, 2012, 12:39 AM
This code is inside my extensions class:
public static class Extensions
{
...
}
and it extends the ConfigurationManager like so
ConfigurationManager.ConnectionStrings.GetMyContext();
Sie StePosted Oct 28, 2012, 12:19 AM
Felipe RamosPosted Oct 27, 2012, 7:41 PM
1. To make the change in the constructor open the DataContext designer.cs file and change the constructors to use your config or app config.
2. In my application I created an extension: