Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Hasani
Guest
 
Posts: n/a
#1: Nov 16 '05
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.



John Wood
Guest
 
Posts: n/a
#2: Nov 16 '05

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


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" <HJB417@hotmail.c0m> wrote in message
news:kNadnUnyL7o9T2zdRVn-jg@comcast.com...[color=blue]
> I'm creating a .net db provider and I came across a weird problem w/ my[/color]
data[color=blue]
> reader.
> The .net provider was created in managed c++ becuase the db api is also[/color]
c++.[color=blue]
> I'm calling the code from a c# project. It shouldn't make a difference but[/color]
I[color=blue]
> did have to do
>[/color]
http://support.microsoft.com/default.aspx?scid=kb;[LN];814472&product=vcNET[color=blue]
> to get my c++ project to compile properly. Anyways, as test i did 'select[/color]
*[color=blue]
> from items' using both an ole db dataadapter and my custom db provider,[/color]
but[color=blue]
> targeting the same database. The items table has about 220 fields and[/color]
3,222[color=blue]
> records. The oledb adapter filled a dataset with no problem. My data[/color]
adapter[color=blue]
> 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[/color]
case)[color=blue]
> it initializes an Array of type Object with a length of 220. It then does[/color]
a[color=blue]
> 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.
>
>[/color]


Hasani
Guest
 
Posts: n/a
#3: Nov 16 '05

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


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.

"Hasani" <HJB417@hotmail.c0m> wrote in message
news:kNadnUnyL7o9T2zdRVn-jg@comcast.com...[color=blue]
> I'm creating a .net db provider and I came across a weird problem w/ my[/color]
data[color=blue]
> reader.
> The .net provider was created in managed c++ becuase the db api is also[/color]
c++.[color=blue]
> I'm calling the code from a c# project. It shouldn't make a difference but[/color]
I[color=blue]
> did have to do
>[/color]
http://support.microsoft.com/default.aspx?scid=kb;[LN];814472&product=vcNET[color=blue]
> to get my c++ project to compile properly. Anyways, as test i did 'select[/color]
*[color=blue]
> from items' using both an ole db dataadapter and my custom db provider,[/color]
but[color=blue]
> targeting the same database. The items table has about 220 fields and[/color]
3,222[color=blue]
> records. The oledb adapter filled a dataset with no problem. My data[/color]
adapter[color=blue]
> 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[/color]
case)[color=blue]
> it initializes an Array of type Object with a length of 220. It then does[/color]
a[color=blue]
> 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.
>
>[/color]


Hasani
Guest
 
Posts: n/a
#4: Nov 16 '05

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


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" <spam@isannoying.com> wrote in message
news:eQJ$yM7ZEHA.1656@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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[/color]
error.[color=blue]
>
> --
> John Wood
> EMail: first name, dot, second name at priorganize.com
>
>
> "Hasani" <HJB417@hotmail.c0m> wrote in message
> news:kNadnUnyL7o9T2zdRVn-jg@comcast.com...[color=green]
> > I'm creating a .net db provider and I came across a weird problem w/ my[/color]
> data[color=green]
> > reader.
> > The .net provider was created in managed c++ becuase the db api is also[/color]
> c++.[color=green]
> > I'm calling the code from a c# project. It shouldn't make a difference[/color][/color]
but[color=blue]
> I[color=green]
> > did have to do
> >[/color]
>[/color]
http://support.microsoft.com/default.aspx?scid=kb;[LN];814472&product=vcNET[color=blue][color=green]
> > to get my c++ project to compile properly. Anyways, as test i did[/color][/color]
'select[color=blue]
> *[color=green]
> > from items' using both an ole db dataadapter and my custom db provider,[/color]
> but[color=green]
> > targeting the same database. The items table has about 220 fields and[/color]
> 3,222[color=green]
> > records. The oledb adapter filled a dataset with no problem. My data[/color]
> adapter[color=green]
> > bombed out when retrieving field 10 of record 563.
> >
> > The problem occurs in my custom data adpater which is used by the[/color][/color]
customer[color=blue][color=green]
> > data adapter. Everytime MyCustomDataReader.Read() is called, (in this[/color]
> case)[color=green]
> > it initializes an Array of type Object with a length of 220. It then[/color][/color]
does[color=blue]
> a[color=green]
> > 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.
> >
> >[/color]
>
>[/color]


Closed Thread