SQL Connection Question

Posted on 2005-05-03
Last Modified: 2010-04-07
I am new here, so please bare with me.  I understand what is going on in the code below.  My problem, is how do I or WHERE do I set the connection to SQL, as far as my Server and such?  This is an example from Microsoft.  I am so used to hard coding the information as in VB6, and getting used to this new stuff now.  This is to fill a datagrid

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim DS As DataSet
        Dim MyConnection As SqlConnection
        Dim MyCommand As SqlDataAdapter

        MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("BenchmarkingString"))
        MyCommand = New SqlDataAdapter("select * from Benchmarking", MyConnection)

        DS = New DataSet
        MyCommand.Fill(DS, "Authors")

        BenchmarkingDataGrid.DataSource = DS.Tables("Benchmarking").DefaultView

    End Sub
Question by:chrisryhal
    LVL 12

    Expert Comment

    It's set in file web.config

    <add key="BenchmarkingString" value="here is the connection string"/>
    LVL 2

    Author Comment

    Actually, there is nothing in the Web.Config like that.  Could you please show me a full example, with a fake connection string to a server.  
    LVL 12

    Accepted Solution

    Your web.config should be like this:

    <?xml version="1.0" encoding="utf-8" ?>
                <add key="BenchmarkingString" value="server=.;database=CWCSReg;uid=sa;password=" />
    LVL 2

    Author Comment

    That is great!!! See, I learn something new everyday.  So now, if I ever want to reference that connection string, I can just call upon my AppSettings.  Thanks a million


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now