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 249259
In Process

The Archive Base Latest Questions

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

I am setting up a .net project that is called to generate other webpages.

  • 0

I am setting up a .net project that is called to generate other webpages. Basically a true CODE BEHIND page. How do I go about making a connection on a Class Library File, when there is no webconfig file present/available?

  • 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. Editorial Team
    Editorial Team
    2026-05-11T21:24:45+00:00Added an answer on May 11, 2026 at 9:24 pm

    In this case, I would create a ‘Base Page’ that derives from System.Web.UI.Page. On this page, you would create a property called ‘ConnectionString’. You will have all of your web pages you create inherit from this page.

    Example:

    public partial class BasePage : System.Web.UI.Page
    {
        protected string ConnectionString
        {
            get
            {
                return System.Configuration.ConfigurationSettings.AppSettings["MyConnectionString"];
            }
        }
    
    }
    

    And in your web.config

    <appSettings>
            <!-- Connection String -->
            <add key="MyConnectionString" value="Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"/>
    </appSettings>
    

    Now you can have a web.config file with a connection string that is easily readable. And you can store this ‘Base Page’ in your class library, no problem. As long as your web pages inheriting from it are using the web.config file with the connection string.

    After that, it’s a simple matter of connecting using that string. You can do this in a variety of ways, either in your web pages, or in separate classes (I recommend separate classes). In this case, if you had a separate class, you would need to pass in the ConnectionString property to your connecting functions:

    public void ExecuteQuery(string connectionString, string sql)
            {
                using (System.Data.SqlClient.SqlConnection theConnection = new System.Data.SqlClient.SqlConnection(connectionString))
                using (System.Data.SqlClient.SqlCommand theCommand = new System.Data.SqlClient.SqlCommand(sql, theConnection))
                {
                    theConnection.Open();
                    theCommand.CommandType = CommandType.Text;
                    theCommand.ExecuteNonQuery();
                }
            }
    

    or you can create a function that does not take a connection string parameter, and just reads from the web.config file. It sounds like you may want to put your connecting and data access code in a class library for good separation of data and content. Hope this helps!

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

Sidebar

Related Questions

I have a multi-project .NET 3.5 solution. It's ASP.NET based with c# code-behind in
In short I'm after a setting in a .net installer project that turns off
I am working on an ASP.NET 4.0 web forms project that uses page routing
net project then it runs in mozilla. I want to change that setting &
In a .NET project, say you have a configuration setting - like a connection
I'm setting up a new project using CruiseControl.net 1.4. I see from ccnet contributions
I'm developing an ASP.Net project. I have an <asp:Table> control on my page, to
Consider the following: I have a .NET 3.5 project that uses a .NET 1.1
Within my Visual Studio 2008 VB.Net project I am opening multiple forms after setting
hello all i have code from open source project that im integrating into my

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.