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

  • Home
  • SEARCH
  • 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 110203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:11:24+00:00 2026-05-11T02:11:24+00:00

I want to seperate the data module of a site into an assembly (

  • 0

I want to seperate the data module of a site into an assembly ( a single dll file ) , What is the best way to get-store and pass the ConnectionString of the site in dealing with the web application . Inside the data assembly I made a static class named ConnectionManager . It has a property named DatabaseConnectionName , that I want to pass and store the connection namewhich is inside Web.Config file . In this strategy I decided to get the name and make the connection in the load time of the website at the Global.asax file and stroe that in the property I mentioned earlier ( DatabaseConnectionName ) . But , This is just the strategy that I used , I dont know what is the common pattern for doing this job .

Parts of code : ===================================== [ ———— Global.asax ———— ]

the code in the site that makes the Data module accessible for the site     void Application_Start(object sender, EventArgs e)      {          OurCompany.Data.ConnectionManager.DatabaseConnectionName = 'MasterConnection';     } 

[ ———— ConnectionManager Class ———— ] this is in the data module apart from the site

public static class ConnectionManager {      public static SqlConnection  GetMasterConnection()     {         string connectionString = ConfigurationManager.ConnectionStrings[**DatabaseConnectionName**].ConnectionString;         SqlConnection conn;              //conn.Open();         conn = new SqlConnection(connectionString);         return  conn;     }      private static string **databaseConnectionName**;     public static string DatabaseConnectionName     {         get         {             return databaseConnectionName;         }         set         {             databaseConnectionName = value;         }     } 

== END ===========================================================

— Questions are : —

  1. Where to store the connection ? ( here was a property inside the ConnectionManager Class , theCompany.Data.ConnectionManager.DatabaseConnectionName )

  2. When make this connection ? ( here was at Global.asax Application Load time )

  3. Which method is best for storing such information : SessionState or ViewState or a simple property

  4. Is this strategy good ? Do you know any better way or the common pattern for this ?

Thanks for any information – MHM –

  • 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-11T02:11:25+00:00Added an answer on May 11, 2026 at 2:11 am

    A few thoughts…

    1. You shouldn’t be storing and hanging onto an open database connection. Open the connection, do your database operations, then close immediately. Apply the rule of acquire late, release early.

    2. See point 1.

    3. Don’t store database connections in session state. See point 1 again. If you mean the connection string, then just read it from the configuration manager when you need it. It’s already cached for you, don’t re-invent or wrap the wheel.

    4. I suggest you take a look at the patterns and practices enterprise library which abstracts away many of the common patterns of managing data access:

    http://www.codeplex.com/entlib

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

Sidebar

Related Questions

I want to be able to store various Canvas items in seperate XAML files
In our web applications, we seperate our Data Access Layers out into their own
Is there a way to use __init__.py to organize multiple files into a module
I have a sting similar to this $_POST[ids]='ABC,DEF,GHI' I want to seperate each of
I have 2 seperate databases with the same structure. I want to move a
I know that with a large site you would want to separate footers, menus,
I have loaded .csv file into the dataset. The csv file(have afew hundreds lines)
We have an application that takes real time data and inserts it into database.
I want to parse an XML file using Perl . I was able to
I have a custom data structure that I want to display in a PyQt

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.