Weird behavior, Program bombs out unless Application.DoEvents() or GC.Collect is called.

H

Hasani

I'm creating a .net db provider and I came across a weird problem w/ my data
reader.
The .net provider was created in managed c++ becuase the db api is also c++.
I'm calling the code from a c# project. It shouldn't make a difference but I
did have to do
http://support.microsoft.com/default.aspx?scid=kb;[LN];814472&product=vcNET
to get my c++ project to compile properly. Anyways, as test i did 'select *
from items' using both an ole db dataadapter and my custom db provider, but
targeting the same database. The items table has about 220 fields and 3,222
records. The oledb adapter filled a dataset with no problem. My data adapter
bombed out when retrieving field 10 of record 563.

The problem occurs in my custom data adpater which is used by the customer
data adapter. Everytime MyCustomDataReader.Read() is called, (in this case)
it initializes an Array of type Object with a length of 220. It then does a
foreach and fills in each cell with the data stored in the record.

Now here's where it gets funky. If I call GC.Collect and/or
System.Windows.Forms.Application.DoEvents() w/ each iteration, it will
retrieve all the records w/ no problems. Doing neither causes the
application to exit and no exception is thrown either. The debug output
shows the exit code as 0. Does anyone have any clues as to why?

The fact that it doesn't throw an exeption is what bothers me the most.
 
J

John Wood

Other times I've seen the app just terminate without message is when there
was a (complicated) stack overflow in a routine that allocates a lot of
memory on the stack... not sure why exactly, but I guess the CLR doesn't
have enough stack space to even run the code that shows the exception error.
 
H

Hasani

I believe this is happening in debug mode only, I made some code changes to
reduce memory usage. I didn't try it in release mode then. But in release
mode, it runs properly. The same problem still occurs in debug mode though,
I'll try to find a larger database table to do further testing.
 
H

Hasani

Ok, I think I fixed the problem. It had something to do with the Linker
settings in the c++ project. I get a warning when I compile now, but it
works!
John Wood said:
Other times I've seen the app just terminate without message is when there
was a (complicated) stack overflow in a routine that allocates a lot of
memory on the stack... not sure why exactly, but I guess the CLR doesn't
have enough stack space to even run the code that shows the exception error.

--
John Wood
EMail: first name, dot, second name at priorganize.com


Hasani said:
I'm creating a .net db provider and I came across a weird problem w/ my data
reader.
The .net provider was created in managed c++ becuase the db api is also c++.
I'm calling the code from a c# project. It shouldn't make a difference
but
I
did have to do
http://support.microsoft.com/default.aspx?scid=kb;[LN];814472&product=vcNET
to get my c++ project to compile properly. Anyways, as test i did
'select
*
from items' using both an ole db dataadapter and my custom db provider, but
targeting the same database. The items table has about 220 fields and 3,222
records. The oledb adapter filled a dataset with no problem. My data adapter
bombed out when retrieving field 10 of record 563.

The problem occurs in my custom data adpater which is used by the customer
data adapter. Everytime MyCustomDataReader.Read() is called, (in this case)
it initializes an Array of type Object with a length of 220. It then
does
a
foreach and fills in each cell with the data stored in the record.

Now here's where it gets funky. If I call GC.Collect and/or
System.Windows.Forms.Application.DoEvents() w/ each iteration, it will
retrieve all the records w/ no problems. Doing neither causes the
application to exit and no exception is thrown either. The debug output
shows the exit code as 0. Does anyone have any clues as to why?

The fact that it doesn't throw an exeption is what bothers me the most.
 

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

Top