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.AppSett ings("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] 7 4078
Close the connection:
conn.Close();
Eliyahu
"Arsalan" <ar***********@hotmail.com> wrote in message
news:eB**************@tk2msftngp13.phx.gbl... 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.AppSett ings("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]
Hi Arsalan.
I think it's a bad idea to return DataReader.
That is because the DataReader holds the connection open,
and you depend on the caller to close it.
I suggest you make a function that returns a DataView.
Sharon.
"Arsalan" <ar***********@hotmail.com> wrote in message
news:eB**************@tk2msftngp13.phx.gbl... 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.AppSett ings("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]
Good idea buddy, but you cannot close the connection and read data from
DataReader [please see the code], and as connection object is out of scope,
you cannot close it through Page_Load event.
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eE**************@TK2MSFTNGP09.phx.gbl... Close the connection:
conn.Close();
Eliyahu
"Arsalan" <ar***********@hotmail.com> wrote in message news:eB**************@tk2msftngp13.phx.gbl... 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.AppSett ings("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]
Thanks,
"Sharon" <sh****@void.null> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl... Hi Arsalan. I think it's a bad idea to return DataReader. That is because the DataReader holds the connection open, and you depend on the caller to close it. I suggest you make a function that returns a DataView. Sharon.
"Arsalan" <ar***********@hotmail.com> wrote in message news:eB**************@tk2msftngp13.phx.gbl... 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.AppSett ings("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]
Take connection object out of that function scope.
Eliyahu
"Arsalan" <ar***********@hotmail.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl... Good idea buddy, but you cannot close the connection and read data from DataReader [please see the code], and as connection object is out of
scope, you cannot close it through Page_Load event. "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message news:eE**************@TK2MSFTNGP09.phx.gbl... Close the connection:
conn.Close();
Eliyahu
"Arsalan" <ar***********@hotmail.com> wrote in message news:eB**************@tk2msftngp13.phx.gbl... 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.AppSett ings("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]
Good suggestion but coding everything would be tedious, is there any
alternate way to do it ??
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OW**************@TK2MSFTNGP09.phx.gbl... Take connection object out of that function scope.
Eliyahu
"Arsalan" <ar***********@hotmail.com> wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl... Good idea buddy, but you cannot close the connection and read data from DataReader [please see the code], and as connection object is out of scope, you cannot close it through Page_Load event. "Eliyahu Goldin" <re*************@monarchmed.com> wrote in message news:eE**************@TK2MSFTNGP09.phx.gbl... > Close the connection: > > conn.Close(); > > Eliyahu > > "Arsalan" <ar***********@hotmail.com> wrote in message > news:eB**************@tk2msftngp13.phx.gbl... >> 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.AppSett ings("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] >> >> > >
> I think it's a bad idea to return DataReader. That is because the DataReader holds the connection open,
That depends upon his application really. Nothing wrong as such as long as,
as you say, it's closed correctly.
DataReader's are supposed to be fast but for small data sets, I've not found
much difference between a DataReader and a DataSet,
Rob. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lebo |
last post by:
Hi
I'm trying to understand how Python handles memory usage and dynamic
object loading and unloading. Problem to solve? Build a very low
memory footprint (non-GUI) Python application for...
|
by: Yasutaka Ito |
last post by:
Hi,
My friend had a little confusion about the working of DataReader after
reading an article from MSDN. Following is a message from him...
<!-- Message starts -->
I was going thru DataReader...
|
by: Ravi |
last post by:
Hi,
I am not able to understand why a datareader needs a connection to the DB
all the time. Here is what I tried.
Sqlcommand cmd = ("select * from table1",con)
// where con is the connection...
|
by: Simon Harvey |
last post by:
Hi All,
I have a colleague that I wprk with that develops using ASP. I develop using
ASP.net.
He seems to make sites much faster than me and I am wondering if its because
of the two different...
|
by: Paolo Pignatelli |
last post by:
I have a Function in a Class File that uses ApplicationBlocks:
Public Function GetProductsByCategory(ByVal CategoryID As Integer)
Dim myConnection As SqlConnection = New...
|
by: Tumurbaatar S. |
last post by:
Is it so important to close database connections?
As I understand, after processing a request and sending a response,
page object destroyed. So all used connections also destroyed.
Yes?
|
by: rockdale |
last post by:
I am using Microsoft.Practices.Enterprise.Library
When I use IDataReader I saw this line
"It is the responsibility of the caller to close the connection and
reader when finished."
I was...
|
by: =?Utf-8?B?UGV0ZXI=?= |
last post by:
I have read some articles state that DataSet should NOT be used for large
resultset. What does "large" mean? Is "large" based on # of rows/columns
and/or memory required to hold the original and...
|
by: =?Utf-8?B?UGV0ZXI=?= |
last post by:
I'm trying to add a datagridview control to a Windows Form to display
read-only information in visual basic 2005. My understanding is that
datareader will be faster for this purpose. I have the...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |