SQL Connection Question

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
Who is Participating?
laotzi2000Connect With a Mentor Commented:
Your web.config should be like this:

<?xml version="1.0" encoding="utf-8" ?>
            <add key="BenchmarkingString" value="server=.;database=CWCSReg;uid=sa;password=" />
It's set in file web.config

<add key="BenchmarkingString" value="here is the connection string"/>
chrisryhalAuthor Commented:
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.  
chrisryhalAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.