,EXE fails when transferred to new PC

I have developed a C# application running on Windows 7 (32 bit) called RBS07.exe which accesses a remote SQL database. It is now ready for testing and so I need to install the .exe on a Windows 7 (64 bit) machine. After compiling on the development box I copied the RBS07.exe to the test PC and set up the appropriate ODBC connections. However when I run this RBS07.exe on the test PC , it displays the 1st window and subsequently crashes (I suspect when attempting to connect to the remote SQL server. The error message is "Unhandled error has occurred in your application - Object reference not set to an instance of an Object"    

The Test PC does not have MS Visual 2010 installed. Is there any way that I can get more information on what is causing the error ?

Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
Add the following event handler to your application, and then redeploy:

// Add at the beginning of your application
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);

// Add this into your program so the above can call it
static void MyHandler(object sender, UnhandledExceptionEventArgs args) 

Open in new window

You should get the full error message and stack trace. This can help you hone in on where in your code the error is occurring.

Raheman M. AbdulConnect With a Mentor Senior Infrastructure Support Analyst & Systems DeveloperCommented:
You can use the stacktrace to trace the error source.

eg: System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace();
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
A few features of the compiler can make a difference in the way things work. The option to enable and disable optimization for instance can lead to problems such as yours (It's under the Advanced Compile Options, in the Compile tab of the project's Properties window.

If you test on your development computer with optimization disabled, which is the default for the Debug configuration, which is the default in the Release configuration, the debugging and release versions do not generate exactly the same code. Although optimization usually increases the performance of the application, it can sometime remove code that makes it crash.

To see if this is the case, deploy a Debug version of the application on the test computer. If the program crashes with the Release version but not with the Debug version, than you are  almost sure that optimization is the cause of the crash.

In such a case, temporarily enabling optimization during debugging on your development station might help you pinpoint the problem and code differently until you find a way to do it that does not trigger the optimizer. It might however leads to some problems in the debugger that will prevent you from being able to use it properly.

The alternative, if you find out that this is the problem, is to remove optimization from the release version. Sometimes, the difference between an optimized and as non-optimized version is so negligible that you can live with it.

If you do not think that optimization could be the problem, you could temporarily install Visual Studio 2010 Express on the test computer and run in there with the source code. You would not have all your development tools, but you would have the whole debugger available to perform your tests.

If it works under inside of Visual Studio, but not when you run the .exe directly, then you would need to look a little further and use the debugger directly on the .exe. Lookup "Jit debugging" in the documentation or MSDN. It will tell you how to configure the application so that the debugger is triggered even when the application is run by launching the .exe outside of Visual Studio. Visual Studio (Express is OK) need to be installed on the test machine for that to work, but it enables you to get the problem exactly as the user would.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.