For reasons that is too long to explain in my .Net Win-Form Application I use a single global OleDbConnection to connect an Access DB. When I need, I open and close the connection, but generally the connection remains opened.
The problem is that sometimes the reading of the data not returns the updated datas:
Using cm As New OleDb.OleDbCommand(sQuery, cn)
Using rd As OleDb.OleDbDataReader = cm.ExecuteReader()
If rd.HasRows Then
If rd.Read() Then
Me.txtBrand.Text = rd.Item("MA_BRAND")
End If
End If
rd.Close()
End Using
End Using
While if I use a new connection I get the right data:
Using cn As New OleDb.OleDbConnection(sConnectionString)
cn.Open()
Using cm As New OleDb.OleDbCommand(sQuery, cn)
Using rd As OleDb.OleDbDataReader = cm.ExecuteReader()
If rd.HasRows Then
If rd.Read() Then
Me.txtBrand.Text = rd.Item("MA_BRAND")
End If
End If
rd.Close()
End Using
End Using
cn.Close()
End Using
I have to use the global connection then my solution is this
cn.Close()
cn.Open()
Using cm As New OleDb.OleDbCommand(sQuery, cn)
But I ask: there is a better solution to refresh the OledbConnection?
Thank you!
Pileggi
The Jet Access engine caches stuff – that’s probably the problem.
Here’s a good link: