bumble_bee_tuna
bumble_bee_tuna

Reputation: 3563

Inject ConStr to Linq to SQL Class in DAL

Sorry if this is a dumb question. I'm writing a simple 3 tier ASP Web Forms app, how can I inject my connection string into my DAL to the LINQ to SQL Class

I believe this is pulling the con info from the App.Config in the DAL

    public LNQDataContext() : 
            base(global::bcDAL.Properties.Settings.Default.TM10_ArchiveConnectionString, mappingSource)
    {
        OnCreated();
    }

is there a way I could modify this to LINQDataContext(string conStr) ?? I really want the admin to be able to set this in the web.config (not have it hard coded in a dll) should he have to move stuff around.

Or any other insightful alternatives are welcome, thanks in advance.

Upvotes: 1

Views: 125

Answers (2)

kman
kman

Reputation: 2257

You can also simply copy your connection string from the app.config of your data layer to the web.config in your presentation layer. The app will find it in the web.config upon execution.

Upvotes: 0

mattmc3
mattmc3

Reputation: 18325

The DataContext class generated for you via the DBML file is a partial, so just extend it with your own class that is named the same and add whatever additional constructor you need. However, I'm not sure why you think the connection string is hard coded with what you have. Dragging tables onto your DBML surface from the Server Explorer already adds a connection string to your web/app.config. That's what global::bcDAL.Properties.Settings.Default.TM10_ArchiveConnectionString is pointing to in your example.

Upvotes: 1

Related Questions