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
        BenchmarkingDataGrid.DataBind()

    End Sub
LVL 2
chrisryhalAsked:
Who is Participating?
 
laotzi2000Connect With a Mentor Commented:
Your web.config should be like this:

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

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

CR
0
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.