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.

Re: Adapter.Fill error by Marina

Marina
Wed Aug 31 11:06:18 CDT 2005

First off, I really recommend not giving variables that are the names of
classes. You should try fixing that first, as it is possible some of the
times you are referencing variables, a class is getting referenced instead.

"Harry F. Harrison" <harryh66@hotmail.com> wrote in message
news:u1SHnUkrFHA.3092@TK2MSFTNGP10.phx.gbl...
> 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.
>



Re: Adapter.Fill error by Harry

Harry
Wed Aug 31 11:42:06 CDT 2005

I renamed my varialbles, and it didn't make a difference. I never use
imports of any kind, so the variable naming issue wouldn't have been a
problem in this case.

Looking at the Adapter class in the Watch window when the exception is
thrown, it looks as though everything is valid. The error doesn't happen on
the first pass of execution, which leads me to think it is something else
under the hood that is getting out of whack.


"Marina" <someone@nospam.com> wrote in message
news:%23UtdrXkrFHA.3852@TK2MSFTNGP15.phx.gbl...
> First off, I really recommend not giving variables that are the names of
> classes. You should try fixing that first, as it is possible some of the
> times you are referencing variables, a class is getting referenced
> instead.
>
> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
> news:u1SHnUkrFHA.3092@TK2MSFTNGP10.phx.gbl...
>> 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.
>>
>
>



Re: Adapter.Fill error by Harry

Harry
Wed Aug 31 12:51:41 CDT 2005

I did a bit of experimenting, and after I open the connection, I'm now doing
a SELECT @@SPID immediately after opening the connection. but this time I'm
calling the SQLCommand.ExecuteReader method, and get the EXACT same error as
below, but this time on the ExecuteReader method.

hmmmm

"Harry F. Harrison" <harryh66@hotmail.com> wrote in message
news:%23IndvrkrFHA.1172@TK2MSFTNGP11.phx.gbl...
>I renamed my varialbles, and it didn't make a difference. I never use
>imports of any kind, so the variable naming issue wouldn't have been a
>problem in this case.
>
> Looking at the Adapter class in the Watch window when the exception is
> thrown, it looks as though everything is valid. The error doesn't happen
> on the first pass of execution, which leads me to think it is something
> else under the hood that is getting out of whack.
>
>
> "Marina" <someone@nospam.com> wrote in message
> news:%23UtdrXkrFHA.3852@TK2MSFTNGP15.phx.gbl...
>> First off, I really recommend not giving variables that are the names of
>> classes. You should try fixing that first, as it is possible some of the
>> times you are referencing variables, a class is getting referenced
>> instead.
>>
>> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
>> news:u1SHnUkrFHA.3092@TK2MSFTNGP10.phx.gbl...
>>> 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.
>>>
>>
>>
>
>



Re: Adapter.Fill error by Marina

Marina
Wed Aug 31 13:03:06 CDT 2005

Instead of giving us the error that the debugger gives you, can you run
without debugging, catch the error in the catch block, and show the message
in a messagebox?

"Harry F. Harrison" <harryh66@hotmail.com> wrote in message
news:OGwJmSlrFHA.1684@TK2MSFTNGP14.phx.gbl...
>I did a bit of experimenting, and after I open the connection, I'm now
>doing a SELECT @@SPID immediately after opening the connection. but this
>time I'm calling the SQLCommand.ExecuteReader method, and get the EXACT
>same error as below, but this time on the ExecuteReader method.
>
> hmmmm
>
> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
> news:%23IndvrkrFHA.1172@TK2MSFTNGP11.phx.gbl...
>>I renamed my varialbles, and it didn't make a difference. I never use
>>imports of any kind, so the variable naming issue wouldn't have been a
>>problem in this case.
>>
>> Looking at the Adapter class in the Watch window when the exception is
>> thrown, it looks as though everything is valid. The error doesn't happen
>> on the first pass of execution, which leads me to think it is something
>> else under the hood that is getting out of whack.
>>
>>
>> "Marina" <someone@nospam.com> wrote in message
>> news:%23UtdrXkrFHA.3852@TK2MSFTNGP15.phx.gbl...
>>> First off, I really recommend not giving variables that are the names of
>>> classes. You should try fixing that first, as it is possible some of
>>> the times you are referencing variables, a class is getting referenced
>>> instead.
>>>
>>> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
>>> news:u1SHnUkrFHA.3092@TK2MSFTNGP10.phx.gbl...
>>>> 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.
>>>>
>>>
>>>
>>
>>
>
>



Re: Adapter.Fill error by Harry

Harry
Thu Sep 08 12:37:15 CDT 2005

Like I thought, it had to do with some other code - in this case, it was
closing a connection inside a finalizer in another class. Wish MS gave a
better exception than NullReferenecException. I was able to track it down
after I turned off connection pooling.

"Marina" <someone@nospam.com> wrote in message
news:%23u%23M3YlrFHA.3440@TK2MSFTNGP10.phx.gbl...
> Instead of giving us the error that the debugger gives you, can you run
> without debugging, catch the error in the catch block, and show the
> message in a messagebox?
>
> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
> news:OGwJmSlrFHA.1684@TK2MSFTNGP14.phx.gbl...
>>I did a bit of experimenting, and after I open the connection, I'm now
>>doing a SELECT @@SPID immediately after opening the connection. but this
>>time I'm calling the SQLCommand.ExecuteReader method, and get the EXACT
>>same error as below, but this time on the ExecuteReader method.
>>
>> hmmmm
>>
>> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
>> news:%23IndvrkrFHA.1172@TK2MSFTNGP11.phx.gbl...
>>>I renamed my varialbles, and it didn't make a difference. I never use
>>>imports of any kind, so the variable naming issue wouldn't have been a
>>>problem in this case.
>>>
>>> Looking at the Adapter class in the Watch window when the exception is
>>> thrown, it looks as though everything is valid. The error doesn't
>>> happen on the first pass of execution, which leads me to think it is
>>> something else under the hood that is getting out of whack.
>>>
>>>
>>> "Marina" <someone@nospam.com> wrote in message
>>> news:%23UtdrXkrFHA.3852@TK2MSFTNGP15.phx.gbl...
>>>> First off, I really recommend not giving variables that are the names
>>>> of classes. You should try fixing that first, as it is possible some
>>>> of the times you are referencing variables, a class is getting
>>>> referenced instead.
>>>>
>>>> "Harry F. Harrison" <harryh66@hotmail.com> wrote in message
>>>> news:u1SHnUkrFHA.3092@TK2MSFTNGP10.phx.gbl...
>>>>> 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.
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>