Link to home
Start Free TrialLog in
Avatar of chrisryhal
chrisryhal

asked on

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
Avatar of laotzi2000
laotzi2000

It's set in file web.config

<appSettings>
<add key="BenchmarkingString" value="here is the connection string"/>
</appSettings>
Avatar of chrisryhal

ASKER

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.  
ASKER CERTIFIED SOLUTION
Avatar of laotzi2000
laotzi2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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