I recently had to add another database connection to my site to get the session values working correctly. What had happened is that the user info my sessions display is held in 2 different databases. I have connection Strings for both databases in my web.config file but until recently, I didn't know that sessions weren't stored unless I had declared <sessionstate> and <httpmodules>.
How do I declare <sessionstate> for a 2nd database? I tried adding a 2nd <sessionstate> in my web.config and my entire site came back with a 500 Internal Error. Below is what I have now, but I need another connection string for sessionState as well. I have also tried just adding a comma after the IBConnectionString and typing in the other connection string, but that didn't work.
<sessionState mode="InProc" cookieless="false" timeout="20" sqlConnectionString="IBConnectionString">
</sessionState>
<httpModules>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</httpModules>
This is my master page's code behind function that sets the session variables and the OnClick from the textbox in which the user enters their code which will then set up the Session. The main session is Session("BAccount"), having this set will then pull the appropriate information from the database in which that user's name is stored.
Protected Sub IBTextBoxButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles IBTextBoxButton.Click
If Page.IsValid Then
Dim LSD As String = CType(Session.Item("LSD"), String)
Dim LSC As String = CType(Session.Item("LSC"), String)
Dim BAccount As String = CType(Session.Item("BAccount"), String)
Session("BAccount") = IBTextBox.Text
If GetCompanyName(LSD) Then
Session("LSD") = LSD
Else
End If
If GetWebsite(LSC) Then
Session("LSC") = LSC
Else
End If
End If
End Sub
Protected Function GetSessionValues(ByVal Code As String) As Boolean
Dim FirstName As String = CType(Session.Item("First_Name"), String)
Dim LastName As String = CType(Session.Item("Last_Name"), String)
Dim Name As String = CType(Session.Item("Name"), String)
If GetAccountName(Code, FirstName, LastName) Then
IBText.Visible = False
IBTextBox.Visible = False
IBTextBoxButton.Visible = False
lblIB.Visible = True
lblIB.Text = "Welcome, " + Session("First_Name") + " " + Session("Last_Name") + "."
lbNotIB.Visible = True
lbNotIB.Text = "Not " + Session("First_Name") + " " + Session("Last_Name") + "?"
Return True
ElseIf GetBackUpAccountName(Code, Name) Then
IBText.Visible = False
IBTextBox.Visible = False
IBTextBoxButton.Visible = False
lblIB.Visible = True
lblIB.Text = "Welcome, " + Session("Name") + "."
lbNotIB.Visible = True
lbNotIB.Text = "Not " + Session("Name") + "?"
Return True
Else
lblIB.ForeColor = Drawing.Color.Red
lblIB.Text = "Account not found, please try again."
Return False
End If
End Function