Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Trying to understand Web.Config AppSetting ConnectionString Properties

Hi All,

I am trying to understand the construction of generic ConnectonString properties in Web.config found in VB.Net 2003. The lsting below was extract from a tutorial book.

Example :
<appSettings>
<add key="Pubs.ConnectionString" value =(local)\NetSDK; Trusted Connection=yes;Database=Pubs" />
</appSettings>

What does (local)\NetSDK means ?
[404 byte] By [Lennie] at [2007-11-11 10:31:55]
# 1 Re: Trying to understand Web.Config AppSetting ConnectionString Properties
"(local)" means that SQL Server is running on the local machine (the Web server), and "NetSDK" is the instance name ( http://msdn2.microsoft.com/en-us/library/aa176582(sql.80).aspx).
Phil Weber at 2007-11-11 23:11:49 >
# 2 Re: Trying to understand Web.Config AppSetting ConnectionString Properties
Hi Phil,

Thank you very much for the information. Now, I have a clear understanding of it and will work on creating the generic ConnectionString.
Lennie at 2007-11-11 23:12:44 >
# 3 Re: Trying to understand Web.Config AppSetting ConnectionString Properties
You may also find this site helpful: http://www.connectionstrings.com/
Phil Weber at 2007-11-11 23:13:53 >
# 4 Re: Trying to understand Web.Config AppSetting ConnectionString Properties
Hi Phil,

Thank you for the URL link relating to Web.Config ConnectionString.
Rgarding your ealier response about "Instance Name" where can I find and have a look. This will help me in the future knowing where to look for it.

Thanks again and Have a Good day.
Lennie at 2007-11-11 23:14:48 >
# 5 Re: Trying to understand Web.Config AppSetting ConnectionString Properties
Hi Phil,

Finally, after following your suggestion I managed to display data using DataList on the Browser.

Enclosed are my scripts which I hope will help other newbies like me.

1. Web.Config
'conPubs is the SQLConnection name

<appSettings>
<add key= "conPubs.ConnectionString "
value = "Server=(Local)\[instance name];Trusted_Connection=yes;Database=pubs" />
</appSettings>

2. Page Load Event
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load

Dim conpubs As New SqlConnection(ConfigurationSettings.AppSettings ("conPubs"))
conPubs.ConnectionString = ConfigurationSettings.AppSettings("conpubs")

daAuthors.Fill(DsAuthors1, "Authors")
Session("DSAuthors") = DsAuthors1
Me.DataBind()

End Sub

3. Display selected item
Private Sub DListAuthor_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DListAuthor.ItemCommand

Dim drwCurrRow As DataRow
Dim dsAuthorSession As DataSet

Select Case e.CommandName
Case "Select"
dsAuthorSession = CType(Session("DsAuthors"), DataSet)
drwCurrRow = dsAuthorSession.Tables("Authors").Rows (e.Item.ItemIndex)

Me.lblFirstName.Text = drwCurrRow("au_Fname").ToString()
Me.lblLastName.Text = drwCurrRow("au_Lname").ToString()
Me.lblPhone.Text = drwCurrRow("Phone").ToString()
Me.lblAddress.Text = drwCurrRow("Address").ToString()
Me.lblCity.Text = drwCurrRow("City").ToString() & ", " & _
drwCurrRow("State").ToString() & " " & _
drwCurrRow("zip").ToString()

End Selec
Lennie at 2007-11-11 23:15:53 >