Thursday, March 22, 2012

OleDbConnection seems to kill Session state

I am working on a simple ASP.NET project with access to an MS Access database. I have noticed that any information stored in Session variables (e.g. Session("Test")) as well as any global parameters (declared as Public ... in a vb module) get reset to Nothing upon postback when a connection was opened (the code works just fine otherwise, i.e. when I don't use any Public variables or Session variable). I have sketched the sequence below.

Any suggestions on what might be happening here and how I might be able to work around this?

Thanks in advance,
Rolf

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Me.IsPostBack Then
Session("Test1") = "Test1"
g_test = "Test1"
'both the Session parameter and g_test have the assigned values
...
Call EstablishConnection()
...
Session("Test2") = "Test2"
g_test = "Test2"
'both the Session parameter and g_test have the assigned values
Else
Dim dummy As String
dummy = CStr(Session("Test"))
'both the Session parameter and g_test are set to Nothing
End If
End SubI found out that there is an issue with where exactly the database file is located. If it located in the /bin folder of the application, ASP.NET seems to draw reset the session (see this link (http://www.dotnet247.com/247reference/msgs/58/290316.aspx)). I now moved the database file to a different folder and everything is working just fine, Session variables and public variables maintain their values.
That's because if anything changes in the /BIN folder the ASP.NET run time assumes the project needs recompiled. You probably also noticed a marked increase in application performance after making your move.
A leftover from winforms programming perhaps? :D

0 comments:

Post a Comment