Adapter.Fill error
- From: "Harry F. Harrison" <harryh66@xxxxxxxxxxx>
- Date: Wed, 31 Aug 2005 09:00:46 -0700
I'm getting the following error on the Adapter.Fill method:
A first chance exception of type 'System.NullReferenceException' occurred in
system.data.dll
Additional information: Object reference not set to an instance of an
object.
Here's the snippet of code:
Friend Function Load(ByVal strSQL As String, ByRef DataSet As
System.Data.DataSet, Optional ByVal strTableName As String = "") As Boolean
Implements IBackendDataProvider.Load
Dim SqlCommand As System.Data.SqlClient.SqlCommand
Dim Adapter As New System.Data.SqlClient.SqlDataAdapter
Dim DoWeClose As Boolean
If Parent.ConnectionString.Length <> 0 Then
DoWeClose = Parent.OpenConditional()
If (DataSet Is Nothing) Then
DataSet = New System.Data.DataSet
End If
SqlCommand = GetSQLCommandObject(strSQL)
SqlCommand.CommandTimeout = Parent.CommandTimeout
Adapter = New System.Data.SqlClient.SqlDataAdapter(SqlCommand)
AddHandler Adapter.FillError, AddressOf FillError
Try
If strTableName.Length <> 0 Then
Adapter.Fill(DataSet, strTableName)
Else
Adapter.Fill(DataSet) ' FAILS HERE - HIGHLIGHTED
GREEN WITH ERROR ABOVE
End If
Catch
Throw
End Try
RemoveHandler Adapter.FillError, AddressOf FillError
Adapter = Nothing
SqlCommand.Dispose()
SqlCommand = Nothing
Parent.CloseConditional(DoWeClose)
End If
End Function
The Adapter.SelectCommand.Connection.State property is set to Open, so I am
assuming that I infact have a valid SelectCommand, and that the connection
is valid.
I have even setup an event handler for the Adapter.FillError event (using
AddHandler), but it doesn't step into that code - it simply throws the
error.
I can duplicate the error, but it doesn't happen the first time the method
is called. I'm thinking it may be connection pool related, or maybe the
connection is opened twice. However, the error is obscure.
.
- Follow-Ups:
- Re: Adapter.Fill error
- From: Marina
- Re: Adapter.Fill error
- Prev by Date: Re: Executescalar, retrieving a value
- Next by Date: Re: Adapter.Fill error
- Previous by thread: Re: SQL Error - PLEASE HELP
- Next by thread: Re: Adapter.Fill error
- Index(es):
Relevant Pages
|