Adapter.Fill error

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.


.



Relevant Pages

  • RE: DropDownList web control in DataGrid
    ... Exception Details: System.NullReferenceException: Object reference not set ... ' CONTRACT PARAM IS DEFINED AS FOLLOWS ... Dim contractParam as IDataParameter = New ... referencing the contract field may be causing my problem. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Object reference not set to an instance of an object.
    ... Object reference not set to an instance of an object. ... An unhandled exception occurred during the execution of the ... Dim myJobRequest As New skillsDB.jobRequest ... Session= "The skills database has been updated ...
    (microsoft.public.dotnet.general)
  • RE: DropDownList web control in DataGrid
    ... ' CONTRACT PARAM IS DEFINED AS FOLLOWS ... Dim contractParam as IDataParameter = New ... I am getting an error "Object reference not set to an instance of an object". ... referencing the contract field may be causing my problem. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: moved from iis5 to iis6
    ... I am at a loss as to why the exact same webpages run on my IIS5 machine. ... Dim oWebUser As cmvWebUser = New cmvWebUser ... Dim oUser As cmvUser = New cmvUser ... Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: moved from iis5 to iis6
    ... I am at a loss as to why the exact same webpages run on my IIS5 machine. ... Dim oWebUser As cmvWebUser = New cmvWebUser ... Dim oUser As cmvUser = New cmvUser ... Object reference not set to an instance of an object. ...
    (microsoft.public.dotnet.framework.aspnet)