Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 56073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:28:38+00:00 2026-05-10T17:28:38+00:00

There is a long running habit here where I work that the connection string

  • 0

There is a long running habit here where I work that the connection string lives in the web.config, a Sql Connection object is instantiated in a using block with that connection string and passed to the DataObjects constructor (via a CreateInstance Method as the constructor is private). Something like this:

using(SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings['ConnectionString'].ConnectionString)) {     DataObject foo = DataObject.CreateInstance(conn);     foo.someProperty = 'some value';     foo.Insert(); } 

This all smells to me.. I don’t know. Shouldn’t the DataLayer class library be responsible for Connection objects and Connection strings? I’d be grateful to know what others are doing or any good online articles about these kind of design decisions.

Consider that the projects we work on are always Sql Server backends and that is extremely unlikely to change. So factory and provider pattern is not what I’m after. It’s more about where responsibility lies and where config settings should be managed for data layer operation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:28:39+00:00Added an answer on May 10, 2026 at 5:28 pm

    I like to code the classes in my data access layer so that they have one constructor that takes an IDbConnection as a parameter, and another that takes a (connection) string.

    That way the calling code can either construct its own SqlConnection and pass it in (handy for integration tests), mock an IDbConnection and pass that in (handy for unit tests) or read a connection string from a configuration file (eg web.config) and pass that in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a long-running msbuild script that I'm trying to speed up. Is there
I have a long running SQL statement that I want to run, and no
I have a a wait form FormWait (long running task notification), that has ShowMessage(string
Is there any way to stop or terminate long running Oracle query in JDBC
Is there a standard linux/unix pattern for communicating with long running process? For example,
I am getting ORA-02049 occasionally for some long-running and/or intensive transactions. There is seemingly
According to Single-Threaded Application with Long-Running Calculation MSDN example, there is a possibility of
Is there any way to disable browsers popups about long running scripts (i.e. in
Wondering if there is a performance difference between letting a long running process hang
i have long running task that gets called using jquery ajax. i am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.