473,796 Members | 2,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with dataset crashing my app

Hi,

using C# asp.net 1.1

I am having a problem. If I use the code below, but have null passed as the
PostingGuid, then by the time I get to fill the dataset, I have "an object
is not set to an instance of an object". This then totally knocks out any
connection to my database for the rest of my application until I terminate
the aspnet process.

Basically, if I have a null PageGuid, then the result from my query will be
empty (not sure if it is null).

If I wrap an if statement around the whole thing (below DS and above return
DS) checking for PostingGuid null, I don't have a problem, but I feel that
this is a hack rather than a fix. Also, there could be a case where
PostingGuid is not null but the return from the database is still empty (or
null)
public DataSet PagePropertiesR ead(string PostingGuid)
{
DataSet DS = new DataSet();

DataAccessLayer .ProviderFactor y DL = new
DataAccessLayer .ProviderFactor y(DB);

string sql = string.Empty;

try
{
conn = DL.CreateConnec tion(Connection String);
conn.Open();

sql = "select * from Page where PageGuid = ? limit 0, 1"; // NOTE:
This is MySQL

cmd = DL.CreateComman d(sql, conn);
cmd = AddParameter(DL , cmd, "@PageGuid" , DbType.String, PostingGuid);

DA = DL.CreateDataAd apter();
DA.SelectComman d = cmd;

DA.Fill(DS); <-- BREAKS HERE

}
catch (Exception ex)
{
string Text = ex.Message;
}
finally
{
conn.Close();
}

return DS;

}

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
May 7 '07 #1
7 1293
On May 7, 12:39 pm, "David"
<david.colliver .N...@revilloc. REMOVETHIS.comw rote:
Hi,

using C# asp.net 1.1

I am having a problem. If I use the code below, but have null passed as the
PostingGuid, then by the time I get to fill the dataset, I have "an object
is not set to an instance of an object". This then totally knocks out any
connection to my database for the rest of my application until I terminate
the aspnet process.

Basically, if I have a null PageGuid, then the result from my query will be
empty (not sure if it is null).

If I wrap an if statement around the whole thing (below DS and above return
DS) checking for PostingGuid null, I don't have a problem, but I feel that
this is a hack rather than a fix. Also, there could be a case where
PostingGuid is not null but the return from the database is still empty (or
null)

public DataSet PagePropertiesR ead(string PostingGuid)
{
DataSet DS = new DataSet();

DataAccessLayer .ProviderFactor y DL = new
DataAccessLayer .ProviderFactor y(DB);

string sql = string.Empty;

try
{
conn = DL.CreateConnec tion(Connection String);
conn.Open();

sql = "select * from Page where PageGuid = ? limit 0, 1"; // NOTE:
This is MySQL

cmd = DL.CreateComman d(sql, conn);
cmd = AddParameter(DL , cmd, "@PageGuid" , DbType.String, PostingGuid);

DA = DL.CreateDataAd apter();
DA.SelectComman d = cmd;

DA.Fill(DS); <-- BREAKS HERE

}
catch (Exception ex)
{
string Text = ex.Message;
}
finally
{
conn.Close();
}

return DS;

}

--
Best regards,
Dave Colliver.http://www.AshfieldFOCUS.com
~~http://www.FOCUSPortals.com- Local franchises available
I think you should provide a value of a null based datatype

I'm not sure if DBNull.Value will help here... try it

May 7 '07 #2
Not quite following?

Do you mean something like...

if (PostingGuid == null)
{
PostingGuid = DBNull.Value;
}

???

Regards,
Dave.

I think you should provide a value of a null based datatype

I'm not sure if DBNull.Value will help here... try it

May 7 '07 #3
On the retrieving end
---------------------
You should input check for a null guid and not even try to retrieve data
where it is null.Based on my reading of your code, this value should never
be null.

Of course, another method is to return an empty dataset when it is null. To
accomplish this, move your query to a stored procedure, where you can
properly branch it (assuming this a database, like SQL Server, of course).
On the binding end
-------------------
Using a DataSet, you have a couple of choices.

1. Hack the DataSet itself and hack out the offending error. This is fine,
with strings (for example), where you can supply a default of String.Empty.
I would not do this with Guid.
2. Edit the binding event of the Data Grid and look for the null there,
where you can supply an empty string for the cell instead, as everything is
converted to string to output to the browser anyway.

If you do it this way, you can remove conditions where a user clicking
something hits a null guid.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************** *************** ***************
Think outside the box!
*************** *************** ***************
"David" <da************ *****@revilloc. REMOVETHIS.comw rote in message
news:uA******** ******@TK2MSFTN GP06.phx.gbl...
Hi,

using C# asp.net 1.1

I am having a problem. If I use the code below, but have null passed as
the PostingGuid, then by the time I get to fill the dataset, I have "an
object is not set to an instance of an object". This then totally knocks
out any connection to my database for the rest of my application until I
terminate the aspnet process.

Basically, if I have a null PageGuid, then the result from my query will
be empty (not sure if it is null).

If I wrap an if statement around the whole thing (below DS and above
return DS) checking for PostingGuid null, I don't have a problem, but I
feel that this is a hack rather than a fix. Also, there could be a case
where PostingGuid is not null but the return from the database is still
empty (or null)
public DataSet PagePropertiesR ead(string PostingGuid)
{
DataSet DS = new DataSet();

DataAccessLayer .ProviderFactor y DL = new
DataAccessLayer .ProviderFactor y(DB);

string sql = string.Empty;

try
{
conn = DL.CreateConnec tion(Connection String);
conn.Open();

sql = "select * from Page where PageGuid = ? limit 0, 1"; // NOTE:
This is MySQL

cmd = DL.CreateComman d(sql, conn);
cmd = AddParameter(DL , cmd, "@PageGuid" , DbType.String, PostingGuid);

DA = DL.CreateDataAd apter();
DA.SelectComman d = cmd;

DA.Fill(DS); <-- BREAKS HERE

}
catch (Exception ex)
{
string Text = ex.Message;
}
finally
{
conn.Close();
}

return DS;

}

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
May 7 '07 #4
On May 7, 2:18 pm, "David"
<david.colliver .N...@revilloc. REMOVETHIS.comw rote:
Not quite following?

Do you mean something like...

if (PostingGuid == null)
{
PostingGuid = DBNull.Value;

}

???

Regards,
Dave.
I think you should provide a value of a null based datatype
I'm not sure if DBNull.Value will help here... try it- Hide quoted text -

- Show quoted text -
yes, but it has to be supported by your DataAccessLayer ... For
example, in ADO.NET, when you have to pass a NULL value to the server,
you should set the db-variable to DBNull.Value.

But, you know what? Try to build sql as

if (PostingGuid == null)
{
sql = "select * from Page where PageGuid IS NULL limit 0, 1";
} else {
sql = "select * from Page where PageGuid = " + PostingGuid.ToS tring()
+ " limit 0, 1";
}

Maybe the problem is in the "IS NULL" construction...

May 7 '07 #5
The guid I am passing is actually a string representation of it. The output
from the database is not actually being displayed but going into an
httpcontext. The system is now quite complex to explain fully how it works,
suffice to say that a page is referenced by a guid string. Theoretically, if
a page is requested that is not represented by a guid string (which is
exactly how I found this problem) then I have to fail gracefully.

Your assumptions are correct. The value should never be null, but it can
happen as I have found out (never considered that particular route.). So,
how do I get around it? I have currently set up an if statement that
compares if it is null and just skips the processing but returns an empty
dataset. This works but it appears to be a hack. (I am not sure what happens
yet if I pass an invalid guid string...)

I will have a go with a couple of possibilities (like Alexey's) and try out
other potential problems (like the one I mention here)

Thanks guys for your assistance...
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

"Cowboy (Gregory A. Beamer)" <No************ @comcast.netNoS pamMwrote in
message news:34******** *************** ***********@mic rosoft.com...
On the retrieving end
---------------------
You should input check for a null guid and not even try to retrieve data
where it is null.Based on my reading of your code, this value should never
be null.

Of course, another method is to return an empty dataset when it is null.
To accomplish this, move your query to a stored procedure, where you can
properly branch it (assuming this a database, like SQL Server, of course).
On the binding end
-------------------
Using a DataSet, you have a couple of choices.

1. Hack the DataSet itself and hack out the offending error. This is fine,
with strings (for example), where you can supply a default of
String.Empty. I would not do this with Guid.
2. Edit the binding event of the Data Grid and look for the null there,
where you can supply an empty string for the cell instead, as everything
is converted to string to output to the browser anyway.

If you do it this way, you can remove conditions where a user clicking
something hits a null guid.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************** *************** ***************
Think outside the box!
*************** *************** ***************
"David" <da************ *****@revilloc. REMOVETHIS.comw rote in message
news:uA******** ******@TK2MSFTN GP06.phx.gbl...
>Hi,

using C# asp.net 1.1

I am having a problem. If I use the code below, but have null passed as
the PostingGuid, then by the time I get to fill the dataset, I have "an
object is not set to an instance of an object". This then totally knocks
out any connection to my database for the rest of my application until I
terminate the aspnet process.

Basically, if I have a null PageGuid, then the result from my query will
be empty (not sure if it is null).

If I wrap an if statement around the whole thing (below DS and above
return DS) checking for PostingGuid null, I don't have a problem, but I
feel that this is a hack rather than a fix. Also, there could be a case
where PostingGuid is not null but the return from the database is still
empty (or null)
public DataSet PagePropertiesR ead(string PostingGuid)
{
DataSet DS = new DataSet();

DataAccessLayer .ProviderFactor y DL = new
DataAccessLaye r.ProviderFacto ry(DB);

string sql = string.Empty;

try
{
conn = DL.CreateConnec tion(Connection String);
conn.Open();

sql = "select * from Page where PageGuid = ? limit 0, 1"; // NOTE:
This is MySQL

cmd = DL.CreateComman d(sql, conn);
cmd = AddParameter(DL , cmd, "@PageGuid" , DbType.String, PostingGuid);

DA = DL.CreateDataAd apter();
DA.SelectComman d = cmd;

DA.Fill(DS); <-- BREAKS HERE

}
catch (Exception ex)
{
string Text = ex.Message;
}
finally
{
conn.Close();
}

return DS;

}

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

May 7 '07 #6
Cool,

You can probably see that I have a function to build the cmd.parameters. I
am passing the value (even if it is null) into the parameters. In my
function, I am now checking if the passed parameter is null and if so,
convert it to DBNull.Value.

In thoery, it will make my code slightly slower I suppose (being checked for
every parameter being passed) but I think it is a much better way of coding
around the problem.

Incidentally, I tried with a value that doesn't exist in my DB. This worked
even though no returned records. That means that the value was meant to be a
DBNull, not just any old null (quite what the difference is between them, I
don't know.)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Alexey Smirnov" <al************ @gmail.comwrote in message
news:11******** *************@l 77g2000hsb.goog legroups.com...
On May 7, 2:18 pm, "David"
<david.colliver .N...@revilloc. REMOVETHIS.comw rote:
>Not quite following?

Do you mean something like...

if (PostingGuid == null)
{
PostingGuid = DBNull.Value;

}

???

Regards,
Dave.
I think you should provide a value of a null based datatype
I'm not sure if DBNull.Value will help here... try it- Hide quoted
text -

- Show quoted text -

yes, but it has to be supported by your DataAccessLayer ... For
example, in ADO.NET, when you have to pass a NULL value to the server,
you should set the db-variable to DBNull.Value.

But, you know what? Try to build sql as

if (PostingGuid == null)
{
sql = "select * from Page where PageGuid IS NULL limit 0, 1";
} else {
sql = "select * from Page where PageGuid = " + PostingGuid.ToS tring()
+ " limit 0, 1";
}

Maybe the problem is in the "IS NULL" construction...

May 7 '07 #7
On May 7, 5:21 pm, "David"
<david.colliver .N...@revilloc. REMOVETHIS.comw rote:
Incidentally, I tried with a value that doesn't exist in my DB. This worked
even though no returned records. That means that the value was meant to be a
DBNull, not just any old null (quite what the difference is between them, I
don't know.)
A null in C# means the absence of a reference to an object. DBNull
means the absence of a known database value.
In thoery, it will make my code slightly slower I suppose (being checked for
every parameter being passed) but I think it is a much better way of coding
around the problem.
You have to do it to avoid the unnecessary exceptions.


May 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2605
by: Mark | last post by:
I am using PHP 4.3.5. I am having a problem in which my script is crashing when it is using a large array. I have simplified the problem down to the following example: <? set_time_limit(0); echo("<html><body>test<br>"); $array1 = array(); $value1 = 1; for ($index = 0; $index < 160000; $index++)
2
1893
by: Suchi | last post by:
Hi all: I want to read a textfile from an ASP program. My program is like this: Set fso = CreateObject("Scripting.FileSystemObject") workFile=http://localhost/Readme.txt) Set textFile = FSObj.OpenTextFile(workFile) lines = split(textFile.ReadAll, VBCrLf) textFile.Close
0
347
by: octaviansen | last post by:
Hi, I am experiencing some weird problems with an ASP.NET web application that is making use of System.Data.DataSet and System.Data.DataRow classes. On a machine with single CPU, the application is running fine. On a machine with Hyperthreading CPU, after a couple of seconds of running OK, the
11
3930
by: neoromance | last post by:
I ran into a weird memory problem. my c++ code got a segmentation error at the execution. why I try to debug it with gdb, I found out it was due to an earlier memory problem. I then used both valgrind and efence tools, both tell me that an early 'new' operation failed. But I have a try{}catch(std:bad_alloc){} block to catch bad memory allocation exceptions. why it wasn't caught?
5
1515
by: John | last post by:
I've started to get session loss on many of my web apps, after only a few minutes (the session lifespan is supposed to be 60 minutes). It occurs in several apps (all on same server), and started happening while I was on ..NET1.1, and continues now I've moved to 2.0 (native 2.0 assemblies compiled using VS2005, not the original VS2003 ones). My session states are very light (most stuff is held in the db). There is plenty of available ram...
2
4407
by: Praesidium | last post by:
I'm having a bit of a problem running a C program I'm working on (compiled in cygwin). There's a way to go, as I'm intent on making sure each bit works before moving on to the next. As it appears now: # include <stdio.h> # include <string.h> int main(void) { printf("Fine at line 6"); FILE *source; char string1;
158
6139
by: jacob navia | last post by:
1: It is not possible to check EVERY malloc result within complex software. 2: The reasonable solution (use a garbage collector) is not possible for whatever reasons. 3: A solution like the one proposed by Mr McLean (aborting) is not possible for software quality reasons. The program must decide
2
1882
by: =?Utf-8?B?QW5uZXh4eHh4eHg=?= | last post by:
My computer keeps crashing. The files created when it does this are: WERdc15.dir00\Mini090708-03.dmp WERdc15.dir00\sysdata.xml has anybody any idea of what these files are and the solution to stopping the computer from crashing? --
2
1588
by: Nelluru | last post by:
Hi, I am using PHP 5.2.5 and IIS 5.1 on Windows XP SP3 machine. I am trying to execute an exe by using exec or system command. When I run this php script from the command line it works fine without any problem. When I try to run the script from IE7 the exe is crashing, sample code: <?php exec("C:\\temp\\uudecode.exe c:\\temp\\test.txt");//or system("cmd.exe /c C:\\temp\\uudecode.exe c:\\temp\\test.txt");
0
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7552
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.