Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 05, 2007 02:39 AM by chetan.sarode
Member
100 Points
179 Posts
Nov 03, 2007 06:37 AM|LINK
I have modified DAL code to work with ms access database.
But after this system shows an error during the code execution:
Private Sub TExecuteReaderCmd(Of T)(ByVal sqlCmd As OleDbCommand, ByVal gcfr As TGenerateListFromReader(Of T), ByRef List As List(Of T)) If ConnectionString = String.Empty Then Throw New ArgumentOutOfRangeException("ConnectionString") End If If sqlCmd Is Nothing Then Throw New ArgumentNullException("sqlCmd") End If Using cn As OleDbConnection = New OleDbConnection(Me.ConnectionString) sqlCmd.Connection = cn cn.Open() sqlCmd.ExecuteReader() gcfr(sqlCmd.ExecuteReader(), List) End Using End Sub
The error is: There is alredy an open DataReader associated with this Connection which must be closed first”
After this I have modified the code. I have skip first sqlcmd.execution ( sqlCmd.ExecuteReader()) and it works,
It's right?
Why this?
And what do the first sqlCmd.ExecuteReader() if I skip it without problem?
All-Star
65839 Points
11163 Posts
Nov 05, 2007 02:39 AM|LINK
You have written following line
sqlCmd.ExecuteReader() gcfr(sqlCmd.ExecuteReader(), List) i.e. you are executing 2 times ExecuteReader()
But for that first you have to close first one again then open
sqlCmd.ExecuteReader()
sqlCmd.Connection.Close();
sqlCmd.Connection.Open(); gcfr(sqlCmd.ExecuteReader(), List)
clembo67
Member
100 Points
179 Posts
TExecuteReaderCmd
Nov 03, 2007 06:37 AM|LINK
I have modified DAL code to work with ms access database.
But after this system shows an error during the code execution:
Private Sub TExecuteReaderCmd(Of T)(ByVal sqlCmd As OleDbCommand, ByVal gcfr As TGenerateListFromReader(Of T), ByRef List As List(Of T))
If ConnectionString = String.Empty Then
Throw New ArgumentOutOfRangeException("ConnectionString")
End If
If sqlCmd Is Nothing Then
Throw New ArgumentNullException("sqlCmd")
End If
Using cn As OleDbConnection = New OleDbConnection(Me.ConnectionString)
sqlCmd.Connection = cn
cn.Open()
sqlCmd.ExecuteReader()
gcfr(sqlCmd.ExecuteReader(), List)
End Using
End Sub
The error is: There is alredy an open DataReader associated with this Connection which must be closed first”
After this I have modified the code. I have skip first sqlcmd.execution ( sqlCmd.ExecuteReader()) and it works,
It's right?
Why this?
And what do the first sqlCmd.ExecuteReader() if I skip it without problem?
chetan.sarod...
All-Star
65839 Points
11163 Posts
Re: TExecuteReaderCmd
Nov 05, 2007 02:39 AM|LINK
You have written following line
sqlCmd.ExecuteReader()
gcfr(sqlCmd.ExecuteReader(), List) i.e. you are executing 2 times ExecuteReader()
But for that first you have to close first one again then open
sqlCmd.ExecuteReader()
sqlCmd.Connection.Close();
sqlCmd.Connection.Open();
gcfr(sqlCmd.ExecuteReader(), List)
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.