473,721 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Managing an invalid cast exception

Hi,

I have built a web application that will be a very high profile application.
We had tested it, demonstrated it and shown that it all works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from the
client and uploads it to the webserver. I suppose part of the original issue
was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results, in
most cases.

The issue arose when we started uploading data in excel. During development
and test, the data in excel was probably being entered in rows, one after
the other. However, during dress rehearsal, the rows are being entered
randomly. Some of you may be aware (as I am now) that excel doesn't
initially care or even know what datatype is in a particular column, so if
you have mixed numbers and words in the same column, depending what goes off
in the first few rows of that column defines what the column data type is.
This appears to override what the column format has been specifically set
to.

The result was that say the first 5 rows had numbers, the sixth row was text
(with the whole column being defined as text), upload, drop direct into a
datagrid or copy to database (database being defined as nvarchar for this
field) the sixth row would then be null. (This was showing even by dropping
the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have already
bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office during
the critical period) than to have it throw the yellow error screen. I can't
write fixes for every possibility, so I need something like a try/catch but
inside the aspx.

2. This question is quite open ended but is about testing. Given my scenario
above, how could/should I have tested in order that it wouldn't have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 19 '05 #1
15 2250
Hi Dave,

The first thing that comes to mind ( and we are probably all guilty to some
degree of this crime, at some time or another ) is that you should always
create a test plan as part of the design, this helps crystallise one's
thinking at the design stage, well before any coding takes place.

Your plan should try and test the data limits which would have helped you
find this particular bug because your data included various potential data
types which is effect a range, along with any illegal things the user might
do. In my experience, a large amount of code tends to be written to prevent
things going wrong rather than simply executing the task you need, and the
absence of a cogent design leads to even further coding. We cant forsee
eveything but good planning is really worth while.

You have two main options as I see it ( and there may well be more ), You
can either validate at the source ( your excel spreadsheet ) or you can
process and validate the data at the transaction stage. I guess the question
is what do I do in each circumstance and how do I manage resolving this for
the user ?, this is also part of your design or should be.

I know this is probably not what you wanted to hear, and others will do
doubt have other views or suggestions, but this is my two euros worth !
--
OHM ( Terry Burns )

http://TrainingOn.net


"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the original
issue was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have
already bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office
during the critical period) than to have it throw the yellow error screen.
I can't write fixes for every possibility, so I need something like a
try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 19 '05 #2
Hi Dave,

The first thing that comes to mind ( and we are probably all guilty to some
degree of this crime, at some time or another ) is that you should always
create a test plan as part of the design, this helps crystallise one's
thinking at the design stage, well before any coding takes place.

Your plan should try and test the data limits which would have helped you
find this particular bug because your data included various potential data
types which is effect a range, along with any illegal things the user might
do. In my experience, a large amount of code tends to be written to prevent
things going wrong rather than simply executing the task you need, and the
absence of a cogent design leads to even further coding. We cant forsee
eveything but good planning is really worth while.

You have two main options as I see it ( and there may well be more ), You
can either validate at the source ( your excel spreadsheet ) or you can
process and validate the data at the transaction stage. I guess the question
is what do I do in each circumstance and how do I manage resolving this for
the user ?, this is also part of your design or should be.

I know this is probably not what you wanted to hear, and others will do
doubt have other views or suggestions, but this is my two euros worth !
--
OHM ( Terry Burns )

http://TrainingOn.net


"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the original
issue was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have
already bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office
during the critical period) than to have it throw the yellow error screen.
I can't write fixes for every possibility, so I need something like a
try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 19 '05 #3
PS, this is not Matlock in Derby is it ? and BTW, nice looking site :)
--
OHM ( Terry Burns )

http://TrainingOn.net

"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the original
issue was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have
already bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office
during the critical period) than to have it throw the yellow error screen.
I can't write fixes for every possibility, so I need something like a
try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 19 '05 #4
PS, this is not Matlock in Derby is it ? and BTW, nice looking site :)
--
OHM ( Terry Burns )

http://TrainingOn.net

"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the original
issue was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have
already bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office
during the critical period) than to have it throw the yellow error screen.
I can't write fixes for every possibility, so I need something like a
try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 19 '05 #5
Hi David,

Ah yes, the demo gods are the most fickle and unkind. The more important
the audience, the more likely a perfectly-running app will misbehave.

Be assured you are not the only victim of these gods' wrath. I once watched
Bill Gates squirm before a huge audience when his demo failed. Did you
notice that he now invites someone else to do the demo while he watches?
<grin>

It sounds like you've got to really scrub the data before you dare do
anything with it. You'll want your SQL query to ensure that every field
returns something that is acceptable as data to its consumer, such as
changing a dbNull to a "" or 0 or false as appropriate.

If something does slip by, you want to avoid yellow screen by using a custom
error page that looks like a part of the site. It reports calmly and
politely that the data provided was not in a usable format and then logs the
real error to the event log:

Displaying Safe Error Messages

http://msdn.microsoft.com/library/de...ormessages.asp
"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the original
issue was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have
already bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office
during the critical period) than to have it throw the yellow error screen.
I can't write fixes for every possibility, so I need something like a
try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available


Nov 19 '05 #6
Hi David,

Ah yes, the demo gods are the most fickle and unkind. The more important
the audience, the more likely a perfectly-running app will misbehave.

Be assured you are not the only victim of these gods' wrath. I once watched
Bill Gates squirm before a huge audience when his demo failed. Did you
notice that he now invites someone else to do the demo while he watches?
<grin>

It sounds like you've got to really scrub the data before you dare do
anything with it. You'll want your SQL query to ensure that every field
returns something that is acceptable as data to its consumer, such as
changing a dbNull to a "" or 0 or false as appropriate.

If something does slip by, you want to avoid yellow screen by using a custom
error page that looks like a part of the site. It reports calmly and
politely that the data provided was not in a usable format and then logs the
real error to the event log:

Displaying Safe Error Messages

http://msdn.microsoft.com/library/de...ormessages.asp
"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the original
issue was lack of knowledge of excel. However, what I then do is open the
spreadsheet and save the contents into SQL Server, the results being
delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%# DataBinder.Eval (Container.Data Item,
"WinningDetail" ) %> in an item template of a datagrid, which I have
already bound to.

Now, with the data coming out of the database being null, I had an invalid
cast exception. How can I protect against that. I would rather fail
gracefully so that I can try and fix it (I will be in the back office
during the critical period) than to have it throw the yellow error screen.
I can't write fixes for every possibility, so I need something like a
try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available


Nov 19 '05 #7
Hi Terry,

Yes, it is Matlock in Derby and thanks for the compliment. The site is part
of a network of portals I developed a few years ago. My local one is
www.AshfieldFOCUS.com.

Anyhow, back to the subject...

I have been developing ASP apps for quite a few years, only recently gone
over to .NET. I have never written a test plan. I wouldn't know how to or
where to start. Apart from that, this particular error was a late comer to
the project.

The spreadsheet was changed, but to me, the error is not the spreadsheet
changing, it is excel for handling its data in a weird way. We had a similar
issue quite early on, where numbers were not showing. I had to get the first
row of each column that was numeric to have the number 0 in it, then
overwrite it when it is needed. To me, this is a hack to overcome the
limitations of excel. However, I could not have foreseen the issue that has
given rise to my message.

In fact, the issue is different on different machines. The site is hosted on
Win2K. I need the first five rows of the spreadsheet to have text in the
column. On my laptop running XP Pro, I have to have many more. I am puzzled.

The only thing I can think of doing, that I don't really want to (as there
are so many columns of data that I need to protect) is to put if statements
around each line of the data coming in. However, this will stop the system
from crashing but doesn't fix the issue. (The screen output can be giving
false information)

I saw on 4guysfromrolla. com an article about test using something called
NUnit. Without practice though, I don't know how I would set up to test. I
will ask one of my colleagues if he has done this sort of testing.

Apart from that, is there any way to wrap the DataBinder.Eval to give me a
chance???

Thanks.
Dave Colliver.
http://www.DerbyFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available
"OHM ( Terry Burns )" <me@mine.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
PS, this is not Matlock in Derby is it ? and BTW, nice looking site :)
--
OHM ( Terry Burns )

http://TrainingOn.net

"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the
original issue was lack of knowledge of excel. However, what I then do is
open the spreadsheet and save the contents into SQL Server, the results
being delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%#
DataBinder.Eval (Container.Data Item, "WinningDetail" ) %> in an item
template of a datagrid, which I have already bound to.

Now, with the data coming out of the database being null, I had an
invalid cast exception. How can I protect against that. I would rather
fail gracefully so that I can try and fix it (I will be in the back
office during the critical period) than to have it throw the yellow error
screen. I can't write fixes for every possibility, so I need something
like a try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available


Nov 19 '05 #8
Hi Terry,

Yes, it is Matlock in Derby and thanks for the compliment. The site is part
of a network of portals I developed a few years ago. My local one is
www.AshfieldFOCUS.com.

Anyhow, back to the subject...

I have been developing ASP apps for quite a few years, only recently gone
over to .NET. I have never written a test plan. I wouldn't know how to or
where to start. Apart from that, this particular error was a late comer to
the project.

The spreadsheet was changed, but to me, the error is not the spreadsheet
changing, it is excel for handling its data in a weird way. We had a similar
issue quite early on, where numbers were not showing. I had to get the first
row of each column that was numeric to have the number 0 in it, then
overwrite it when it is needed. To me, this is a hack to overcome the
limitations of excel. However, I could not have foreseen the issue that has
given rise to my message.

In fact, the issue is different on different machines. The site is hosted on
Win2K. I need the first five rows of the spreadsheet to have text in the
column. On my laptop running XP Pro, I have to have many more. I am puzzled.

The only thing I can think of doing, that I don't really want to (as there
are so many columns of data that I need to protect) is to put if statements
around each line of the data coming in. However, this will stop the system
from crashing but doesn't fix the issue. (The screen output can be giving
false information)

I saw on 4guysfromrolla. com an article about test using something called
NUnit. Without practice though, I don't know how I would set up to test. I
will ask one of my colleagues if he has done this sort of testing.

Apart from that, is there any way to wrap the DataBinder.Eval to give me a
chance???

Thanks.
Dave Colliver.
http://www.DerbyFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available
"OHM ( Terry Burns )" <me@mine.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
PS, this is not Matlock in Derby is it ? and BTW, nice looking site :)
--
OHM ( Terry Burns )

http://TrainingOn.net

"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the
original issue was lack of knowledge of excel. However, what I then do is
open the spreadsheet and save the contents into SQL Server, the results
being delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%#
DataBinder.Eval (Container.Data Item, "WinningDetail" ) %> in an item
template of a datagrid, which I have already bound to.

Now, with the data coming out of the database being null, I had an
invalid cast exception. How can I protect against that. I would rather
fail gracefully so that I can try and fix it (I will be in the back
office during the critical period) than to have it throw the yellow error
screen. I can't write fixes for every possibility, so I need something
like a try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available


Nov 19 '05 #9
Hi Ken,

Thanks for that. Its funny when you see it happen to someone else. When it
happens to you, you just want to curl up into a ball and die. This was a
practice run through. My bosses bosses boss just happened to be there. Only
a few days earlier, she was singing my praises after hearing so many
positive remarks about me.

Anyhow, back to the issue...

I have

*************** *************** *************** *********
string excelConnectStr ing = "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source="
+ CurrentLocation + @"\upload\sourc edata.xls" + ";Extended Properties=Exce l
8.0;";
OleDbConnection excelConn = new OleDbConnection (excelConnectSt ring);
excelConn.Open( );

OleDbCommand objCmdSelect = new OleDbCommand("S elect * from [DataSheet$]",
excelConn);

OleDbDataAdapte r excelAdapter = new OleDbDataAdapte r();

excelAdapter.Se lectCommand = objCmdSelect;

DataSet excelDataset = new DataSet();

excelAdapter.Fi ll(excelDataset , "XLData");

*************** *************** *************** **********

I am then doing a foreach on the datarows.

Is there an option to open the spreadsheet and read all the raw data as
data, rather than excel trying to intepret what it thinks I should be
reading? (Mind you, that could be a problem as well, as the sheet I am
reading also has formula. I need to read the results of the formulae.)

I will look at the yellow page fix, as it might be suitable for the rest of
our site. Hopefully, it will have the facility where I can set it to email
us of any errors.

Thanks.
Dave Colliver.
http://www.SwindonFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:OH******** ******@tk2msftn gp13.phx.gbl...
Hi David,

Ah yes, the demo gods are the most fickle and unkind. The more important
the audience, the more likely a perfectly-running app will misbehave.

Be assured you are not the only victim of these gods' wrath. I once
watched Bill Gates squirm before a huge audience when his demo failed. Did
you notice that he now invites someone else to do the demo while he
watches? <grin>

It sounds like you've got to really scrub the data before you dare do
anything with it. You'll want your SQL query to ensure that every field
returns something that is acceptable as data to its consumer, such as
changing a dbNull to a "" or 0 or false as appropriate.

If something does slip by, you want to avoid yellow screen by using a
custom error page that looks like a part of the site. It reports calmly
and politely that the data provided was not in a usable format and then
logs the real error to the event log:

Displaying Safe Error Messages

http://msdn.microsoft.com/library/de...ormessages.asp
"David" <da************ *****@revilloc. REMOVETHIS.com> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Hi,

I have built a web application that will be a very high profile
application. We had tested it, demonstrated it and shown that it all
works.

On a dress rehearsal run through, it failed spectacularly. I was so
embarrassed and felt like killing the person that made it fail. However,
when it goes live, IT MUST NOT FAIL.

The system has a backoffice system that takes an excel spreadsheet from
the client and uploads it to the webserver. I suppose part of the
original issue was lack of knowledge of excel. However, what I then do is
open the spreadsheet and save the contents into SQL Server, the results
being delivered from SQL to the website.

The front end displays the results. I am using various controls, such as
datagrids, datalists and even labels. Many of the datagrids/datalists etc
are not autogenerating. I use container.datai tem to display the results,
in most cases.

The issue arose when we started uploading data in excel. During
development and test, the data in excel was probably being entered in
rows, one after the other. However, during dress rehearsal, the rows are
being entered randomly. Some of you may be aware (as I am now) that excel
doesn't initially care or even know what datatype is in a particular
column, so if you have mixed numbers and words in the same column,
depending what goes off in the first few rows of that column defines what
the column data type is. This appears to override what the column format
has been specifically set to.

The result was that say the first 5 rows had numbers, the sixth row was
text (with the whole column being defined as text), upload, drop direct
into a datagrid or copy to database (database being defined as nvarchar
for this field) the sixth row would then be null. (This was showing even
by dropping the excel data direct into the datagrid)

This absolutely caught me out. I was forced to accept responsibility even
though it was not my fault. :-(

Anyhow, now I have explained the situation, I have 2 questions.
1. In the ASP.NET page, I am using <%#
DataBinder.Eval (Container.Data Item, "WinningDetail" ) %> in an item
template of a datagrid, which I have already bound to.

Now, with the data coming out of the database being null, I had an
invalid cast exception. How can I protect against that. I would rather
fail gracefully so that I can try and fix it (I will be in the back
office during the critical period) than to have it throw the yellow error
screen. I can't write fixes for every possibility, so I need something
like a try/catch but inside the aspx.

2. This question is quite open ended but is about testing. Given my
scenario above, how could/should I have tested in order that it wouldn't
have failed?

Thanks for your time.

Best regards,
Dave Colliver.
http://www.MatlockFOCUS.com
~~
http://www.FOCUSPortals.com - Portal Franchises available

Nov 19 '05 #10

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

Similar topics

3
1311
by: Simon | last post by:
Hi all, Do you think the best way to avoid the problems of nulls in the database is just to provide default values via the db schema? Alternatively, is it better to allow nulls, seeing as the "absence" of data is an entirely valid and useful value? If the later is true, is there a better way to handle nulls that doing this for each and every column of each and every table? I'm hoping there is
0
1685
by: Alan Z. Scharf | last post by:
Win Server 2003 VS.Net 2003 --------------- 1. I'm having the same problem below on all six of my pages with a datagrid item. 2. These pages all worked fine for months until problem started. 3. Same problem on two different computers running Win 2003.
5
3431
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS 5), but fails on IIS 6 running on a Win2003 server. The web uses Pages derived from a custom class I wrote (which itself derives from Page) to provide some common functionality. The Page_Load handler the failing webpage starts out like this: ...
3
2290
by: John Howard | last post by:
Making the following call to a local MSAccess database works fine: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim intRows As Integer Dim strSQL As String Dim ds As New DataSet ' Create connection Dim cn As New OleDbConnection With cn .connectionstring =
1
4903
by: Hifni Shahzard | last post by:
Hi, I got a stored procedure, where it returns a value. But if I execute it. It gives an error as "Invalid cast from System.Int32 to System.Byte.". To make clear how do I execute this, below I'm specifiying my code: The Code used in Visual Studio: Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As String, ByVal iDate As Date) As String 'Dim Ret As Integer
9
2200
by: buzz | last post by:
I am attempting to pass data between two asp.net web forms pages. I have found the method to do this on the msdn site here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconPassingServerControlValuesBetweenPages.asp After attempting to do this myself, I kept getting an Invalid Cast Exception error, so I finally resorted to simply copying and pasting the MS code in this article into two pages for the...
0
820
by: David | last post by:
Hi, I have built a web application that will be a very high profile application. We had tested it, demonstrated it and shown that it all works. On a dress rehearsal run through, it failed spectacularly. I was so embarrassed and felt like killing the person that made it fail. However, when it goes live, IT MUST NOT FAIL. The system has a backoffice system that takes an excel spreadsheet from the
6
2611
by: cs_hart | last post by:
I am getting an invalid cast exception - cast from string to type double is not valid. Dim curName As String Dim prevName As String = "" curName = CStr(rows.Item(i).Item(colSchName)) ' extract name from database row If (curName.CompareTo(prevName <> 0)) Then <--- exception occurs on this line
7
3622
by: Chris Thunell | last post by:
I'm trying to loop through an exchange public folder contact list, get some information out of each item, and then put it into a vb.net datatable. I run though the code and all works fine until i get to item 250 i get a "system.invalid cast exception" and "specified cast is not valid". Once i get this error and try to go to the next record.. every record after gets the same error... It's like the com connection to outlook has been lost....
0
8738
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
9085
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...
0
8026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6678
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
4499
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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
2
2596
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2146
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.