Re: SqlDataReader Function From a VB6 refugee



The Return statement returns immediately (code beyond this point will not be
reached)

Also the Reader is for connected operations i.e. the underlying connection
should be open (it's likely closed not because of you explicit statmenet
that is not reached but likely because of the using statement that dispose
the connection)...

--
Patrice

"Paul Ilacqua" <pilacqu2@xxxxxxxxxxxx> a écrit dans le message de news:
eKCdmWMVGHA.5828@xxxxxxxxxxxxxxxxxxxxxxx
All,
I'm trying to create a DataReader Function to call from within my
class to open a simple datareader.
I have thoroughly read the Data Access Patterns and practices and do not
believe in using canned code right off the bat. I want to rebuild the
canned code so I understand it, then I may use it or use my own understood
version.

The error message is in Error Text: Message="Invalid attempt to Read when
reader is closed."


'===================== This is call to function ===================
Dim dr As SqlDataReader = Create_SQL_DataReader("20060213")
While dr.Read() !!! Errs here
End While
'===================== End call to function ===================

Shared Function Create_SQL_DataReader(ByVal sDate As String) As
SqlDataReader

Dim SQLConn As New SqlConnection(sConn)
Using SQLConn

' This Builds SQL String into "s" and uses passed in param
"sDate"
Dim s As String = BuildShiftSQL(sDate)

Dim Cmd = New SqlCommand(s, SQLConn)
SQLConn.Open()
Dim iDr As SqlDataReader = Cmd.ExecuteReader()
Return iDr
s = String.Empty
SQLConn.Close()
SQLConn.Dispose()
End Using
End Function

Error Text:
System.InvalidOperationException was unhandled
Message="Invalid attempt to Read when reader is closed."
Source="System.Data"
StackTrace:
at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean
setTimeout)
at System.Data.SqlClient.SqlDataReader.Read()
at WindowsApplication1.dataReaderDataSetForm.Main() in
C:\Data\VBExpress\Parts\Parts\Form1.vb:line 20
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()




.



Relevant Pages

  • Re: Array of UDT
    ... reader and not reader ... Excel, PowerPoint, and VBA add-ins, tutorials ... r_sname As String ... Dim rngCommRng As Range ...
    (microsoft.public.excel.programming)
  • Re: Array of UDT
    ... "Tushar Mehta" wrote: ... readers() to reader ... r_sname As String ... Dim rngCommRng As Range ...
    (microsoft.public.excel.programming)
  • Re: Array of UDT
    ... readers() to reader ... r_sname As String ... Dim rngCommRng As Range ... Dim bCommArr() As Boolean ...
    (microsoft.public.excel.programming)
  • Re: Array of UDT
    ... Does the compiler highlight a particular line as the offending line? ... readers() to reader ... r_sname As String ... Dim rngCommRng As Range ...
    (microsoft.public.excel.programming)
  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)