A
Arsalan
I have a function which return datareader
Public Shared Function ReturnDReader(ByVal query As String) As
OleDbDataReader
Dim Connection_String As String =
System.Configuration.ConfigurationSettings.AppSettings("strConn")
Dim conn As OleDbConnection
Dim cm As OleDbCommand
Dim dr As OleDbDataReader
Try
conn = New OleDbConnection(Connection_String)
cm = New OleDbCommand(query, conn)
conn.Open()
dr = cm.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
Catch ExceptRaise As OleDbException
'ExceptRaise.Message()
Finally
cm.Dispose()
End Try
End Function
I call this function like this from Page_Load method
Dim d As Data.OleDb.OleDbDataReader
d = CodeMaster.Func.ReturnDReader("select * from employess")
DataList1.DataSource = d
DataList1.DataBind()
d.Close()
But for some reason after closing the datareader, the database is not
closing. (I'm using Access and record locking file is still there)
How do I resolve this ? [If the function's code is copied to the Page_Load
method then everything works fine, but problem occurs when this function is
in external class. the database doesnt close]
Public Shared Function ReturnDReader(ByVal query As String) As
OleDbDataReader
Dim Connection_String As String =
System.Configuration.ConfigurationSettings.AppSettings("strConn")
Dim conn As OleDbConnection
Dim cm As OleDbCommand
Dim dr As OleDbDataReader
Try
conn = New OleDbConnection(Connection_String)
cm = New OleDbCommand(query, conn)
conn.Open()
dr = cm.ExecuteReader(CommandBehavior.CloseConnection)
Return dr
Catch ExceptRaise As OleDbException
'ExceptRaise.Message()
Finally
cm.Dispose()
End Try
End Function
I call this function like this from Page_Load method
Dim d As Data.OleDb.OleDbDataReader
d = CodeMaster.Func.ReturnDReader("select * from employess")
DataList1.DataSource = d
DataList1.DataBind()
d.Close()
But for some reason after closing the datareader, the database is not
closing. (I'm using Access and record locking file is still there)
How do I resolve this ? [If the function's code is copied to the Page_Load
method then everything works fine, but problem occurs when this function is
in external class. the database doesnt close]