"Object reference not set to an intance of an object." when attempting to fill my dataset

  • Thread starter Thread starter R. G.
  • Start date Start date
R

R. G.

I get the following error intermittenly when attempting to fill my
dataset in an ASP.NET project:

Object reference not set to an intance of an object.
Exception Details: System.NullReferenceException: Object reference not
set to an intance of an object.

The code I'm running in the page_load event and looks like this:

userNamesDA.Fill(userNamesDS, "userNames")

I'm using an Access database located on the same machine hosting my
app, a 2.4 Ghz, 512 MB, Compaq EVO Workstation running Windows XP Pro.
The error comes up about 5% of the time while in debugging mode. It
doesn't seem to occur as often in production, but the system hasn't
been tested all that extensively yet since its still in development.
When the error does come up, refreshing the page takes care of the
problem. I've also had the same error occurr while performing the
same operation against a Sybase database, and again, it seems to be
intermittent.

Any ideas what's causing this? I have a feeling that the connection
to the database is not being established before the call to fill the
dataset is executed.

Is there anyway to test whether that connection is "live" before
executing the Fill method? Or could the problem be hardware since I'm
not running the application off a Windows Server optimized to handle
these kinds of applications? I'm just frustrated with the
inconsistancy of the problem. If it happened all the time, I would
have a better chance of debugging it.
 
Hi,

R. G. said:
I get the following error intermittenly when attempting to fill my
dataset in an ASP.NET project:

Object reference not set to an intance of an object.
Exception Details: System.NullReferenceException: Object reference not
set to an intance of an object.

Which object? Is userNamesDA created, is userNamesDS created?
The code I'm running in the page_load event and looks like this:

userNamesDA.Fill(userNamesDS, "userNames")

Is there anyway to test whether that connection is "live" before
executing the Fill method? Or could the problem be hardware since I'm
not running the application off a Windows Server optimized to handle
these kinds of applications? I'm just frustrated with the
inconsistancy of the problem. If it happened all the time, I would
have a better chance of debugging it.

DataAdapter initializes (and closes) the connection if it isn't open.
You can check the connection state by examining connection.State property.
You might put the Fill statament into try/catch block and set a breakpoint
inside catch.
 
Thanks for the reply. First, I'm not sure which object the error is
referring to. All I know is that Fill method is causing the problem.
I'm assuming the problem is with the data adapter because I can't see
how the data set could be causing a problem. IMHO, its more likely that
the data adapter would have some problem establishing a connection than
my dataset having a problem being filled. Can't really justify it, just
a hunch.

I was thinking of using something like this:

if not userNamesDA = Nothing then
userNamesDA.Fill(userNamesDS, "userNames")
else
alert the user of a problem OR try again?
end if

The problem with any of these attempts is that I can't test them to see
if they even worked. The problem pops up so intermittingly like I said.
Sometimes its on the first load up of the first page of my application,
sometimes I don't see it for days. I happen to be in one of those
spells currently. But I know it will eventually rear its ugly head when
I least expect it, like during the demonstration for our directors next
month.
 
This is in my class declarations:

Protected WithEvents userNamesDA As System.Data.OleDb.OleDbDataAdapter
Protected WithEvents userNamesDS As ConfRoomScheduler.usernamesDS

This stuff is in my InitializeComponent() method:

Me.userNamesDA = New System.Data.OleDb.OleDbDataAdapter
Me.userNamesDS = New ConfRoomScheduler.userNamesDS
...........
CType(Me.userNamesDS,
System.ComponentModel.ISupportInitialize).BeginInit()
......
Me.userNamesDS.DataSetName = "userNamesDS"
Me.userNamesDS.Locale = New System.Globalization.CultureInfo("en-US")
........
CType(Me.userNamesDS,
System.ComponentModel.ISupportInitialize).EndInit()


Since I'm fairly new to .Net, I've been using the VS.NET wizards to
create my ADO.NET objects, such as the data adapters and sets. Perhaps
that's where I'm going wrong!
 
Back
Top