I normally store all my configs in the registry. Even though I have started using LINQ I would not like to have the DSN in the web.config, but rather let it stay in the registry and attach it (maybe in the Application Start Event) to the System Config.
How can this be done?
Thanx for any ideas!
edit: to make it clear: I do not want to write to the web.config file, I just want to keep the dsn (encrypted) anywhere else than the web.config, so I have the same web.config on all development stages (local, staginf, live, backup).
Christoph
Solution Code in VB.Net:
1) Add a new Class, with one method, which inherits from the original Datacontext:
Public Class MyDatabaseDataContext Inherits DatabaseDataContext Public Sub New() MyBase.New(Settings.DSN) End Sub End Class
2) Use this Class in all Linq Datasources instead of the original Context.
ContextTypeName='MyProject.MyDatabaseDataContext
Here’s what I do. I have a a base class for my DataContext. It’s called DataContextBase and is generated by sqlmetal.exe. I have a derived class called DataContext which is what is used in my Linq calls. It looks like this:
I have a static class in my library called ConnectionHolder which stores the connection string:
(note: this is separate from DataContext because there are places in my app outside of Linq that I use the connection string). At app startup I say ConnectionHolder.ConnectionString = (wherever you store the connection string).