runs in debug but not in production

S

Scott

I have a simple asp.net app which works fine in debug mode, but crashes on
the following line when I run it on the production server:

Dim dt As DataTable

I have tried the following variations which produce the same result:
Dim dt As System.Data.DataTable
Dim dt As DataTable = New DataTable

The error message reads: System.NullReferenceException: Object reference
not set to an instance of an object.

This is the only place in code that dt is declared. Funny that this will
work in debug and error out in production. Does anyone have any ideas? I
am out. :)

Scott
 
M

Marina

I would think there is something else going on, like the production server
has some files out of date. So the line number that is shown when it
crashes isn't actually the code being executed.
 
S

Steven Cheng[MSFT]

Hi Scott,

Thanks you for using Microsoft Newsgroup Service. Based on your
description, one of your web page will running into "Null reference"
exception on production server, however runs ok on debug environment? Also,
you thought the problem is due to a "DataTable" variable. Is my
understanding of your problem correct?

If so, I think you may first try confirming the actual object which caused
the exception. Since you run to the exception on Production server, you may
add some code such as"

If dt is Nothing Then
.....

Or other to confirm whether the DataTable variable is the root caused of
the problem. In addition, I think Marina's suggestion is also considerable,
maybe you can reboot the web application or the web server? Or try creating
another page which does the has the same functions and operations in it and
run it on both debug and production server to see whether the problem
remain.


Please try out the preceding suggestions and let me know if you need any
help.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Scott

Alright I did the following:
1) Went to Microsoft's web site and did an update on anything it wanted to
update (the server is a Windows 2000 Pro OS)
2) Downloaded the latest .NET framework version (1.1 Redistributable
Package) and ran it on the server.
3) I opened the solution in VS and ran a build on it, saved the files and
then copied the whole directory from my inetpub/wwwroot directory to the
production directory on the server (after deleting all the files on the
server related to the project).

I even checked the references on the project to make sure I knew where they
were pointing to. I suspect this may be the problem. I have 2 references
in the project. I have them built as DLLs on my hard drive. I created a
reference to their DLLs from the main project and I see that VS dropped them
into the bin directory for the main project. The 2 sub-projects that allow
me to code the DLLs are also included in my solution for my application. Is
there somewhere else I should point them to?

Maybe it has nothing to do with that. Since my changes I am getting the
same error on the following line of code which follows the one I described
previously:

dt = ds.tables(0)

The error message (assuming it is showing me the right line of code) seems
to indicate it can't get a reference for an object, but the ds and dt
variables are declared properly.

Please!!!! Any thoughts on this would be appreciated! This isn't supposed
to happen in .NET!!!!

Scott
 
J

John Miner

1) Did you rebuild the 2 referenced projects after downloading the .NET 1.1
framework?

2) Are you sure the dataset is properly instantiated and that it contains at
least one datatable?

HTH
 
J

John Miner

1) Did you rebuild the 2 referenced projects after downloading the .NET 1.1
framework?

2) Are you sure the dataset is properly instantiated and that it contains at
least one datatable?

HTH
 
S

Scott

I went and clicked on "Build" on the pop-up menus for each sub project and
then the main project. Earlier, I was clicking on Debug/build in VS which I
assumed did the whole solution. Is there something else I need to do?

I will list my code here that instantiates the relevant variables, but I
should point out that this code works fine in debug mode in VS and also if I
run it on the development server when I access the site with:
http://localhost/project. If I use the server name or IP address (ie.
http://server1/project) It errors out. In fact, the only way I can get the
error message itself and not the generic version of the error, is to go to
the server and try to run the code with the server name or IP address. I
hope that gives you good clues.

The line of code it stops on is part of the following set:

=================================================================
Public Class DecPat1
...
Public ds As DataSet
...
Public Sub HandleCommands(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
...
ds = CType(Session("MyData"), DataSet)
Dim dt As System.Data.DataTable
dt = ds.Tables(0)
...
End Sub
...
End Class
=================================================================

I have tried variations of the "Dim dt As ..." line. As far as whether or
not I am using the correct table inside of the Tables collection, I only
know that it works in debug mode, so I think that tells me I am referencing
it properly.

I hope this helps. Please let me know what additional information you could
use or what you think.

Scott

PS. I ran the framework redistributable on my workstation and on the server
just now... just to be on the safe side and try to rule that out. :)
 
M

mikeb

Scott said:
I went and clicked on "Build" on the pop-up menus for each sub project and
then the main project. Earlier, I was clicking on Debug/build in VS which I
assumed did the whole solution. Is there something else I need to do?

I will list my code here that instantiates the relevant variables, but I
should point out that this code works fine in debug mode in VS and also if I
run it on the development server when I access the site with:
http://localhost/project. If I use the server name or IP address (ie.
http://server1/project) It errors out. In fact, the only way I can get the
error message itself and not the generic version of the error, is to go to
the server and try to run the code with the server name or IP address. I
hope that gives you good clues.

The line of code it stops on is part of the following set:

=================================================================
Public Class DecPat1
...
Public ds As DataSet
...
Public Sub HandleCommands(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
...
ds = CType(Session("MyData"), DataSet)
Dim dt As System.Data.DataTable
dt = ds.Tables(0)
...
End Sub
...
End Class
=================================================================

I have tried variations of the "Dim dt As ..." line. As far as whether or
not I am using the correct table inside of the Tables collection, I only
know that it works in debug mode, so I think that tells me I am referencing
it properly.

I hope this helps. Please let me know what additional information you could
use or what you think.

Scott

PS. I ran the framework redistributable on my workstation and on the server
just now... just to be on the safe side and try to rule that out. :)

Your problem will have nothing to do with the declarations of the
variables - you need to check at runtime to see that your DataSet or
DataTable references are non-null.

Your code snippet shows that you're getting the dataset from the Session
collection, but it doesn't show how the dataset is created in the first
place.

In any case, add the following lines of code right after you get the
dataset reference from the Sessoin collection - it should help you get
closer to the cause of the problem:

If ds Is Nothing Then
Trace.Warn("DataSet is Null")
Return
End If

If ds.Tables Is Nothing Then
Trace.Warn("ds.Tables is Null")
Return
End If

And add a trace="true" attribute to the aspx page's @Page directive.

Now when you navigate to that page, you'll get trace output added to the
bottom, and there will be a line written in red indicating which
reference is null.

You'll have to debug some other part of your application to find out why.
 
K

KatB

Just a thought, but have you confirmed that RIGHTS are set correctly to
the queries used to populate the session variable you use as your
datasource?

For example, in SQL Server 2000 (or whatever you use) you may need to
set permissions on these queries depending on your setup. Sometimes the
username/passwords are different from dev server to production server.

I'll admit to once spending quite a bit of debug time only to have that
be the cause (blush)...now it's the first thing I check if I know my
query returns the dataset in SQL Analyzer, etc.,but I get Nothing for
the dataset.

Good luck.

Kat
 
S

Scott

Mike,
I added the code you mentioned and was able to make it run on my
workstation... I added an "Else... trace.warn("DataSet is NOT null")" to
each of the sections so I could confirm that it got to that line of code. I
also added a "Return" right after the test code so it doesn't try to run the
rest of the procedure. On my workstation this all runs fine whether I run
in debug mode or access the code through IE with
//localhost/directory/pagename and I get the red lines in the stack trace on
the aspx page with the "NOT null" messages.

I copy the code to the server and get different results. If I try to run it
in IE with "//<servername>/<directory>/ I get "Object Reference Not set to
an instance of an object". If I use "//localhost/<directory>/ it runs fine
but I don't see the trace messages in red... I get the trace info, just not
our messages.

I started wondering if the problem is with the way that I am releaseing the
application to the server or the server itself. I have another machine here
available to me with Windows 2000 Server loaded and normally used as a
SQL2000 server but has IIS on it, so I loaded dotnetfx.exe on it, did not
reboot, dropped the files from my workstation's inetpub/wwwroot/project1
directory into inetpub/wwwroot/project1 on the server and tried to run the
program throuh IE on that server with
//localhost/testzone/project1/decpat.aspx. I got an error screen saying
"Server Error in '/' Application". It is referencing the "authentication
mode="windows"" line in web.config and suggesting I should create a virtual
directory. So, I set one up with Read, Run, Execute and Write permissions
and everything works great (although I don't see the red statements in the
trace).

So, I go back to the first server and remove the virtual directory I was
using and add it back again, this time making sure to check the Read, Run,
Execute and Write boxes. When I try to run the code I get an error saying
that "Object Not Set to and Instance Of An Object". So, I have the same
code on both servers, but one server will not run it. Question is: Why?
Could it be that I did not release it to the first server properly? Is
there a better way to release a project? Any other reasons for this that
you can think of would also be appreciated.

Thank you for your time in helping me to understand this issue.

Scott

BTW: I don't think permissions are an issue because I am running 2 other
applications on the first server that do similar tasks with the same SQL
server database and not having any problems.
 
S

Steven Cheng[MSFT]

Hi Scott,


Thank you the response. Based on the information you provided, the problem
is likely due to the server enviroment. As you said that the same
application run well on another server. Can you find any difference between
the two servers? Such as enviroment settting(framework version, IIS setting
or ..). Also, I recommend that you create a new simple web application just
with one page which has some similar database operations then run this web
application in all those servers to see whether the problem remain. If the
problem still remains with such a simple web application, I think we could
confirm it due to the server enviroment.

Please check out my suggestion and let me know if you need any helps.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
M

mikeb

Scott said:
Mike,
I added the code you mentioned and was able to make it run on my
workstation... I added an "Else... trace.warn("DataSet is NOT null")" to
each of the sections so I could confirm that it got to that line of code. I
also added a "Return" right after the test code so it doesn't try to run the
rest of the procedure. On my workstation this all runs fine whether I run
in debug mode or access the code through IE with
//localhost/directory/pagename and I get the red lines in the stack trace on
the aspx page with the "NOT null" messages.

I copy the code to the server and get different results. If I try to run it
in IE with "//<servername>/<directory>/ I get "Object Reference Not set to
an instance of an object". If I use "//localhost/<directory>/ it runs fine
but I don't see the trace messages in red... I get the trace info, just not
our messages.

I think that means that the updated .aspx file is being copied to the
server, but the updated code-behind dll is not. The .aspx file has the
@Page directive which enables the trace (which you're seeing). But, the
code-behind DLL has the calls to Trace.Warn(). Sine the Trace.Warn()
messages are not being seen, it seems that the dll is not being copied over.

Of course, I'm assuming that you're using a code-behind model.

I can't think of why you'd get different behavior using //<servername>
and //localhost, unless there is DNS, WINS or host file issues.

Does a simple "hello word" .aspx page work in that virtual directory?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top