views:

2581

answers:

6

I have a client/server application using the .Net 2.0 Framework. I'm using Visual Studio 2008 to build and manage code.

When I run either a Debug or Release version of the application simply by starting the .exe, I get an insert statement on the database that tries to insert a "0" for the foreign key of a table, triggering an error because the primary key of the other table is not 0.

When I run the application by hitting the play buttton ("Start Debugging"), the insert statement uses the correct foreign key.

In the first case, this happens even when I "Attach to Process" to the Debug version after it's started.


My question: what's the difference between attaching to the debug version of the application after it has started and starting the application from the debugger?

A: 

As far as I know, only the hosting process. Have you tried disabling it as per here?

Stu
Just to add: the hosting process can be disabled for the project by going to properties > debug.
Brian Rasmussen
Actually, my Start Action is already the .exe file. I have a solution with one of the class libraries, so I don't start it directly.
Mark A Johnson
+1  A: 

Without more detail, it's hard to say. However, to hazard an underinformed guess, I'd bet you're seeing a timing issue (race condition or some such). For whatever reason, your server (I presume) is getting spurious data when started 'normally'. Starting it up through the IDE/debugger causes a delay that allows the client process (again, an assumption) time to get correct data to the server.

Harper Shelby
A: 

Could it be compiler optimizations? When you start the process under the debugger, the JIT compiler doesn't do compiler optimizations.

ChrisW
But those optimizations are shut off whenever the Debug build is run (if you leave the configuration at the default). So they should be off in my "run the .exe" case, as well.
Mark A Johnson
+2  A: 

If you "Start Debugging", you'll run under the vshost.exe hosting process. This recycles the AppDomain creation, lets you debug partial trust apps, and can sandbox ClickOnce apps.

None of these features are likely causes for your bug (and vshost hasn't been much of an issue for most) - so I think this is probably a red herring.

You should probably be looking at multithreaded and timing issues related to getting the FK value instead.

Mark Brackett
A: 

Are you sure the .exe you are starting/attaching to is the build output of your project?

Gus Paul
Yes, I'm sure it's the build output.
Mark A Johnson
A: 

I know it sounds silly, but a good idea would be to check if you have the correct parameters, it is easy to forget that we add them to the debugger but not release.