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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:12:14+00:00 2026-05-22T20:12:14+00:00

I am developing a site using ASP.NET, SQL 2008 and LINQ. I want to

  • 0

I am developing a site using ASP.NET, SQL 2008 and LINQ. I want to ask about the connection string. I have made a class like that to get the datacontext in each page:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public static class DatabaseConnection
{
    static DataClassesDataContext datacontext;    
    public static DataClassesDataContext getConnection()
    {
       datacontext = new DataClassesDataContext(@"Data Source=localhost;Initial Catalog=dbname; Integrated Security=True");
        return datacontext;
    }
}

Is that a correct way to get the connection in each page?

Also about ‘Data Source’, when I deploy the site what will it be? And what is the difference between data source and address keywords?

  • 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-22T20:12:15+00:00Added an answer on May 22, 2026 at 8:12 pm

    That is a valid way of getting the data context instance, yes. You can use Data Source or Server I believe.

    Please be aware that DataContext is IDisposable, so make sure it’s not left hanging around after usage, I tend to do:

    using (var context = DataHelper.GetContext())
    {
       // Stuff.
    }
    

    Also, you should really put your connection strings in the configuration file:

    <connectionStrings>
       <add name="Live" connectionString="blah;"/>
    </connectionStrings>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been developing a site using ASP.NET MVC, and have decided to use the
I am developing an ASP.net site (using .NET 4, EF, jQuery Ajax, SQL Server
Using ASP.NET MVC3 C# AND MS SQL 2008 I'm developing a Software As Service
I am developing a site using asp.net and C# ( framework 1.1 ). Theres
I am using ASP.NET MVC for developing a web site. I am using jquery
I'm developing an ASP.NET application for an intranet site that is using Windows/NTLM/WIA/whatever authentication.
I am developing a multilingual ASP.NET web site. I want the users to be
I'm developing web site using asp.net. In my web site after login i set
I am developing a site using ASP.NET 2.0. AjaxToolKit's ModalPopupExtender is being used to
I am tasked with developing a multi lingual site using ASP.NET MVC. For static

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.