Garbage collector has problems with ADO-MD interop

  • Thread starter Thread starter Elyo Ravuna
  • Start date Start date
E

Elyo Ravuna

Our ADO-MD application sometimes gives the
exception 'Object is no longer valid'.

You can reproduce the problem using the following code.

Module main
'When "enable optimizations" is set and the code is
'not run in the Visual Studio IDE, the following code
'gives the exception 'object is no longer valid'.
'The aim of GC.Collect() is to make the bug reproducible.
Public Sub main()
Try
Dim MyConnection As New ADODB.Connection
Dim MyCellset As New ADOMD.Cellset
Dim MyPosition As ADOMD.Position
Dim Dummy As String
MyConnection.Open("provider=msolap;data
source=localhost;initial catalog=Foodmart 2000")
MyCellset.Open("select Time.Year.Members on 0 from
[Sales] where [Unit Sales]", MyConnection)
For Each MyPosition In MyCellset.Axes(0).Positions
GC.Collect() : GC.WaitForPendingFinalizers()
Dummy = MyPosition.Members(0).UniqueName
Next
Catch ex As Exception
MsgBox("Message:" + ex.Message + vbCrLf + "Source:"
+ ex.Source + vbCrLf + "StackTrace:" +
ex.StackTrace, , "Exception")
End Try
End Sub
End Module


When I replace the for-each loop with an index loop, the
code runs fine. Should I replace all for-each loops with
index loops in our application?

Sincerely,
Elyo Ravuna
 
Hi Elyo,

Both ADODB and ADOMD are unmanaged codes. Although they are running in VB
..NET, they're not created on managed heap. So, you cannot release them by
calling GC.Collect().

Furthermore, garbage collection is managed by the .net framework. It will
be called automatically when there's not enough free memory. Please leave
it to the .net framework, or it might hit the performance of your
application.

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Elyo Ravuna" <[email protected]>
| Sender: "Elyo Ravuna" <[email protected]>
| Subject: Garbage collector has problems with ADO-MD interop
| Date: Fri, 26 Sep 2003 01:09:52 -0700
| Lines: 40
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54790
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Our ADO-MD application sometimes gives the
| exception 'Object is no longer valid'.
|
| You can reproduce the problem using the following code.
|
| Module main
| 'When "enable optimizations" is set and the code is
| 'not run in the Visual Studio IDE, the following code
| 'gives the exception 'object is no longer valid'.
| 'The aim of GC.Collect() is to make the bug reproducible.
| Public Sub main()
| Try
| Dim MyConnection As New ADODB.Connection
| Dim MyCellset As New ADOMD.Cellset
| Dim MyPosition As ADOMD.Position
| Dim Dummy As String
| MyConnection.Open("provider=msolap;data
| source=localhost;initial catalog=Foodmart 2000")
| MyCellset.Open("select Time.Year.Members on 0 from
| [Sales] where [Unit Sales]", MyConnection)
| For Each MyPosition In MyCellset.Axes(0).Positions
| GC.Collect() : GC.WaitForPendingFinalizers()
| Dummy = MyPosition.Members(0).UniqueName
| Next
| Catch ex As Exception
| MsgBox("Message:" + ex.Message + vbCrLf + "Source:"
| + ex.Source + vbCrLf + "StackTrace:" +
| ex.StackTrace, , "Exception")
| End Try
| End Sub
| End Module
|
|
| When I replace the for-each loop with an index loop, the
| code runs fine. Should I replace all for-each loops with
| index loops in our application?
|
| Sincerely,
| Elyo Ravuna
|
|
 
We do NOT have any GC.Collect() in our original code.

Users of our application started to get the
message "object is no longer valid" randomly.

Having an error message randomly made me think of the
garbage collector, so I tried to put some GC.Collect()
calls in the code in order to make the bug reproducible.

GC.Collect() should not cause the code to fail. However,
in our case:

- Without GC.Collect() the code "sometimes" gives an error
message.
- With GC.Collect() the code "always" gives an error
message.

I isolated the problem in a very short program. I would be
very glad if you could examine the code in my first
message. The problem could be reproduced on any machine.
(Our .net framework version is 1.1)

Sincerely,
Elyo Ravuna

-----Original Message-----
Hi Elyo,

Both ADODB and ADOMD are unmanaged codes. Although they are running in VB
.NET, they're not created on managed heap. So, you cannot release them by
calling GC.Collect().

Furthermore, garbage collection is managed by the .net framework. It will
be called automatically when there's not enough free memory. Please leave
it to the .net framework, or it might hit the performance of your
application.

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Elyo Ravuna" <[email protected]>
| Sender: "Elyo Ravuna" <[email protected]>
| Subject: Garbage collector has problems with ADO-MD interop
| Date: Fri, 26 Sep 2003 01:09:52 -0700
| Lines: 40
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54790
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Our ADO-MD application sometimes gives the
| exception 'Object is no longer valid'.
|
| You can reproduce the problem using the following code.
|
| Module main
| 'When "enable optimizations" is set and the code is
| 'not run in the Visual Studio IDE, the following code
| 'gives the exception 'object is no longer valid'.
| 'The aim of GC.Collect() is to make the bug reproducible.
| Public Sub main()
| Try
| Dim MyConnection As New ADODB.Connection
| Dim MyCellset As New ADOMD.Cellset
| Dim MyPosition As ADOMD.Position
| Dim Dummy As String
| MyConnection.Open("provider=msolap;data
| source=localhost;initial catalog=Foodmart 2000")
| MyCellset.Open("select Time.Year.Members on 0 from
| [Sales] where [Unit Sales]", MyConnection)
| For Each MyPosition In MyCellset.Axes(0).Positions
| GC.Collect() : GC.WaitForPendingFinalizers()
| Dummy = MyPosition.Members(0).UniqueName
| Next
| Catch ex As Exception
| MsgBox("Message:" + ex.Message + vbCrLf + "Source:"
| + ex.Source + vbCrLf + "StackTrace:" +
| ex.StackTrace, , "Exception")
| End Try
| End Sub
| End Module
|
|
| When I replace the for-each loop with an index loop, the
| code runs fine. Should I replace all for-each loops with
| index loops in our application?
|
| Sincerely,
| Elyo Ravuna
|
|

.
 
Hi Elyo,

I cannot reproduce the error message "object is no longer valid" on my
computer. Can you tell me on which line was the exception thrown?

Here are two KB articles which might be related with this issue. HTH.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Elyo Ravuna" <[email protected]>
| Sender: "Elyo Ravuna" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: Garbage collector has problems with ADO-MD interop
| Date: Mon, 29 Sep 2003 00:37:09 -0700
| Lines: 125
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOGXH0mYbiGa7MsRladdJgbBhs71A==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54940
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| We do NOT have any GC.Collect() in our original code.
|
| Users of our application started to get the
| message "object is no longer valid" randomly.
|
| Having an error message randomly made me think of the
| garbage collector, so I tried to put some GC.Collect()
| calls in the code in order to make the bug reproducible.
|
| GC.Collect() should not cause the code to fail. However,
| in our case:
|
| - Without GC.Collect() the code "sometimes" gives an error
| message.
| - With GC.Collect() the code "always" gives an error
| message.
|
| I isolated the problem in a very short program. I would be
| very glad if you could examine the code in my first
| message. The problem could be reproduced on any machine.
| (Our .net framework version is 1.1)
|
| Sincerely,
| Elyo Ravuna
|
|
| >-----Original Message-----
| >Hi Elyo,
| >
| >Both ADODB and ADOMD are unmanaged codes. Although they
| are running in VB
| >.NET, they're not created on managed heap. So, you cannot
| release them by
| >calling GC.Collect().
| >
| >Furthermore, garbage collection is managed by the .net
| framework. It will
| >be called automatically when there's not enough free
| memory. Please leave
| >it to the .net framework, or it might hit the performance
| of your
| >application.
| >
| >Does this answer your question? If anything is unclear,
| please feel free to
| >reply to the post.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties, and
| confers no
| >rights."
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Elyo Ravuna" <[email protected]>
| >| Sender: "Elyo Ravuna" <[email protected]>
| >| Subject: Garbage collector has problems with ADO-MD
| interop
| >| Date: Fri, 26 Sep 2003 01:09:52 -0700
| >| Lines: 40
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| >| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| >| Newsgroups: microsoft.public.dotnet.framework
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework:54790
| >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| >|
| >| Our ADO-MD application sometimes gives the
| >| exception 'Object is no longer valid'.
| >|
| >| You can reproduce the problem using the following code.
| >|
| >| Module main
| >| 'When "enable optimizations" is set and the code is
| >| 'not run in the Visual Studio IDE, the following code
| >| 'gives the exception 'object is no longer valid'.
| >| 'The aim of GC.Collect() is to make the bug
| reproducible.
| >| Public Sub main()
| >| Try
| >| Dim MyConnection As New ADODB.Connection
| >| Dim MyCellset As New ADOMD.Cellset
| >| Dim MyPosition As ADOMD.Position
| >| Dim Dummy As String
| >| MyConnection.Open("provider=msolap;data
| >| source=localhost;initial catalog=Foodmart 2000")
| >| MyCellset.Open("select Time.Year.Members on 0
| from
| >| [Sales] where [Unit Sales]", MyConnection)
| >| For Each MyPosition In MyCellset.Axes(0).Positions
| >| GC.Collect() : GC.WaitForPendingFinalizers()
| >| Dummy = MyPosition.Members(0).UniqueName
| >| Next
| >| Catch ex As Exception
| >| MsgBox("Message:" + ex.Message + vbCrLf
| + "Source:"
| >| + ex.Source + vbCrLf + "StackTrace:" +
| >| ex.StackTrace, , "Exception")
| >| End Try
| >| End Sub
| >| End Module
| >|
| >|
| >| When I replace the for-each loop with an index loop,
| the
| >| code runs fine. Should I replace all for-each loops
| with
| >| index loops in our application?
| >|
| >| Sincerely,
| >| Elyo Ravuna
| >|
| >|
| >
| >.
| >
|
 
Hi Elyo,

Sorry I forgot to post the URLs on my last post. They are:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;309327

and

http://support.microsoft.com/default.aspx?scid=KB;EN-US;318263

Another suggestion: try to check if the analysis server is installed
properly on the server. And check the MDAC in your local machine. Try to
upgrade the MDAC to 2.7, which is available at
http://download.microsoft.com.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Elyo Ravuna" <[email protected]>
| Sender: "Elyo Ravuna" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: Garbage collector has problems with ADO-MD interop
| Date: Mon, 29 Sep 2003 00:37:09 -0700
| Lines: 125
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOGXH0mYbiGa7MsRladdJgbBhs71A==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54940
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| We do NOT have any GC.Collect() in our original code.
|
| Users of our application started to get the
| message "object is no longer valid" randomly.
|
| Having an error message randomly made me think of the
| garbage collector, so I tried to put some GC.Collect()
| calls in the code in order to make the bug reproducible.
|
| GC.Collect() should not cause the code to fail. However,
| in our case:
|
| - Without GC.Collect() the code "sometimes" gives an error
| message.
| - With GC.Collect() the code "always" gives an error
| message.
|
| I isolated the problem in a very short program. I would be
| very glad if you could examine the code in my first
| message. The problem could be reproduced on any machine.
| (Our .net framework version is 1.1)
|
| Sincerely,
| Elyo Ravuna
|
|
| >-----Original Message-----
| >Hi Elyo,
| >
| >Both ADODB and ADOMD are unmanaged codes. Although they
| are running in VB
| >.NET, they're not created on managed heap. So, you cannot
| release them by
| >calling GC.Collect().
| >
| >Furthermore, garbage collection is managed by the .net
| framework. It will
| >be called automatically when there's not enough free
| memory. Please leave
| >it to the .net framework, or it might hit the performance
| of your
| >application.
| >
| >Does this answer your question? If anything is unclear,
| please feel free to
| >reply to the post.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties, and
| confers no
| >rights."
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Elyo Ravuna" <[email protected]>
| >| Sender: "Elyo Ravuna" <[email protected]>
| >| Subject: Garbage collector has problems with ADO-MD
| interop
| >| Date: Fri, 26 Sep 2003 01:09:52 -0700
| >| Lines: 40
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| >| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| >| Newsgroups: microsoft.public.dotnet.framework
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework:54790
| >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| >|
| >| Our ADO-MD application sometimes gives the
| >| exception 'Object is no longer valid'.
| >|
| >| You can reproduce the problem using the following code.
| >|
| >| Module main
| >| 'When "enable optimizations" is set and the code is
| >| 'not run in the Visual Studio IDE, the following code
| >| 'gives the exception 'object is no longer valid'.
| >| 'The aim of GC.Collect() is to make the bug
| reproducible.
| >| Public Sub main()
| >| Try
| >| Dim MyConnection As New ADODB.Connection
| >| Dim MyCellset As New ADOMD.Cellset
| >| Dim MyPosition As ADOMD.Position
| >| Dim Dummy As String
| >| MyConnection.Open("provider=msolap;data
| >| source=localhost;initial catalog=Foodmart 2000")
| >| MyCellset.Open("select Time.Year.Members on 0
| from
| >| [Sales] where [Unit Sales]", MyConnection)
| >| For Each MyPosition In MyCellset.Axes(0).Positions
| >| GC.Collect() : GC.WaitForPendingFinalizers()
| >| Dummy = MyPosition.Members(0).UniqueName
| >| Next
| >| Catch ex As Exception
| >| MsgBox("Message:" + ex.Message + vbCrLf
| + "Source:"
| >| + ex.Source + vbCrLf + "StackTrace:" +
| >| ex.StackTrace, , "Exception")
| >| End Try
| >| End Sub
| >| End Module
| >|
| >|
| >| When I replace the for-each loop with an index loop,
| the
| >| code runs fine. Should I replace all for-each loops
| with
| >| index loops in our application?
| >|
| >| Sincerely,
| >| Elyo Ravuna
| >|
| >|
| >
| >.
| >
|
 
Hello Kevin,

The exception does not appear inside Visual Studio.
You have to build an EXE file, and run the EXE from the
command prompt.

Also, you have to make sure that "enable optimizations" is
set in project properties. Otherwise, the exception does
not appear.

If you still cannot reproduce the problem, I will conclude
that the problem is specific to our configuration.

Thanks in advance,
Elyo

P.S.: The call that throws the exception
is 'MyPosition.Members(0).UniqueName'.

-----Original Message-----
Hi Elyo,

I cannot reproduce the error message "object is no longer valid" on my
computer. Can you tell me on which line was the exception thrown?

Here are two KB articles which might be related with this issue. HTH.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Elyo Ravuna" <[email protected]>
| Sender: "Elyo Ravuna" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: Garbage collector has problems with ADO-MD interop
| Date: Mon, 29 Sep 2003 00:37:09 -0700
| Lines: 125
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOGXH0mYbiGa7MsRladdJgbBhs71A==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:54940
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| We do NOT have any GC.Collect() in our original code.
|
| Users of our application started to get the
| message "object is no longer valid" randomly.
|
| Having an error message randomly made me think of the
| garbage collector, so I tried to put some GC.Collect()
| calls in the code in order to make the bug reproducible.
|
| GC.Collect() should not cause the code to fail. However,
| in our case:
|
| - Without GC.Collect() the code "sometimes" gives an error
| message.
| - With GC.Collect() the code "always" gives an error
| message.
|
| I isolated the problem in a very short program. I would be
| very glad if you could examine the code in my first
| message. The problem could be reproduced on any machine.
| (Our .net framework version is 1.1)
|
| Sincerely,
| Elyo Ravuna
|
|
| >-----Original Message-----
| >Hi Elyo,
| >
| >Both ADODB and ADOMD are unmanaged codes. Although they
| are running in VB
| >.NET, they're not created on managed heap. So, you cannot
| release them by
| >calling GC.Collect().
| >
| >Furthermore, garbage collection is managed by the .net
| framework. It will
| >be called automatically when there's not enough free
| memory. Please leave
| >it to the .net framework, or it might hit the performance
| of your
| >application.
| >
| >Does this answer your question? If anything is unclear,
| please feel free to
| >reply to the post.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties, and
| confers no
| >rights."
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Elyo Ravuna" <[email protected]>
| >| Sender: "Elyo Ravuna" <[email protected]>
| >| Subject: Garbage collector has problems with ADO-MD
| interop
| >| Date: Fri, 26 Sep 2003 01:09:52 -0700
| >| Lines: 40
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| >| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| >| Newsgroups: microsoft.public.dotnet.framework
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework:54790
| >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| >|
| >| Our ADO-MD application sometimes gives the
| >| exception 'Object is no longer valid'.
| >|
| >| You can reproduce the problem using the following code.
| >|
| >| Module main
| >| 'When "enable optimizations" is set and the code is
| >| 'not run in the Visual Studio IDE, the following code
| >| 'gives the exception 'object is no longer valid'.
| >| 'The aim of GC.Collect() is to make the bug
| reproducible.
| >| Public Sub main()
| >| Try
| >| Dim MyConnection As New ADODB.Connection
| >| Dim MyCellset As New ADOMD.Cellset
| >| Dim MyPosition As ADOMD.Position
| >| Dim Dummy As String
| >| MyConnection.Open("provider=msolap;data
| >| source=localhost;initial catalog=Foodmart 2000")
| >| MyCellset.Open("select Time.Year.Members on 0
| from
| >| [Sales] where [Unit Sales]", MyConnection)
| >| For Each MyPosition In MyCellset.Axes (0).Positions
| >| GC.Collect() : GC.WaitForPendingFinalizers()
| >| Dummy = MyPosition.Members(0).UniqueName
| >| Next
| >| Catch ex As Exception
| >| MsgBox("Message:" + ex.Message + vbCrLf
| + "Source:"
| >| + ex.Source + vbCrLf + "StackTrace:" +
| >| ex.StackTrace, , "Exception")
| >| End Try
| >| End Sub
| >| End Module
| >|
| >|
| >| When I replace the for-each loop with an index loop,
| the
| >| code runs fine. Should I replace all for-each loops
| with
| >| index loops in our application?
| >|
| >| Sincerely,
| >| Elyo Ravuna
| >|
| >|
| >
| >.
| >
|

.
 
Hi Elyo,

Please try to check which adodb library you're refering. There are two
libraries in .net Add Reference dialog box. One is under .net tab, while
the other is under COM tab. Try to remove the current reference to adodb,
and add reference to the one under .net tab. Please refer to the following
article for more information:

http://support.microsoft.com/default.aspx?scid=kb;en-us;318559

I also found that you're using ADODB.Connection to connect to a OLAP
service. It might work, however, I recommend you use ADOMD.Catalog to
connect to it. The following is a code sample for your reference:

<%@ Language=VBScript %>
<%
'***************************************************************************
*********
'***************************************************************************
*********
'*** Active Server Page displays OLAP data from default
'*** MDX Query string and writes resulting cell set to HTML table
'*** structure.
'***************************************************************************
*********
'***************************************************************************
*********
Response.Buffer=True
Response.Expires=0
%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY bgcolor=Ivory>
<FONT FACE=Verdana>

<%

Dim cat,cst,i,j,strSource,csw,intDC0,intDC1,intPC0, intPC1

'***************************************************************************
*********
'*** Set Connection Objects for Multi dimensional Catalog and Cell Set
'***************************************************************************
*********
Set cat = Server.CreateObject("ADOMD.Catalog")
Set cst = Server.CreateObject("ADOMD.CellSet")

'***************************************************************************
*********
'*** Use default settings of a known OLAP Server
'*** for Server Name for Connection Set Server Name Session Object
'*** to default value
'***************************************************************************
*********
'***************************************************************************
*********
'*** Must set OLAPServerName to OLAP Server that is
'*** present on network
'***************************************************************************
*********
OLAPServerName = "Please set to present OLAP Server"
cat.ActiveConnection = "Data Source=" & OLAPServerName & ";Initial
Catalog=FoodMart;Provider=msolap;"

'***************************************************************************
*********
'*** Use default MDX Query string of a known query
'*** that works with default server Set MDXQuery Session Object to default
value
'***************************************************************************
*********
strSource = strSource & "SELECT "
strSource = strSource & "{[Measures].members} ON COLUMNS,"
strSource = strSource & "NON EMPTY [Store].[Store City].members ON ROWS"
strSource = strSource & " FROM Sales"

'***************************************************************************
*********
'*** Set Cell Set Source property to strSource to be passed on cell set
open method
'***************************************************************************
*********
cst.Source = strSource

'***************************************************************************
*********
'*** Set Cell Sets Active connection to use the current Catalogs Active
connection
'***************************************************************************
*********
Set cst.ActiveConnection = cat.ActiveConnection

'***************************************************************************
*********
'*** Using Open method, Open cell set
'***************************************************************************
*********
cst.Open

'***************************************************************************
*********
'*** Set Dimension Counts minus 1 for Both Axes to intDC0, intDC1
'*** Set Position Counts minus 1 for Both Axes to intPC0, intPC1
'***************************************************************************
*********
intDC0 = cst.Axes(0).DimensionCount-1
intDC1 = cst.Axes(1).DimensionCount-1

intPC0 = cst.Axes(0).Positions.Count - 1
intPC1 = cst.Axes(1).Positions.Count - 1

'***************************************************************************
*********
'*** Create HTML Table structure to hold MDX Query return Record set
'***************************************************************************
*********
Response.Write "<Table width=100% border=1>"

'***************************************************************************
*********
'*** Loop to create Column header
'***************************************************************************
*********
For h=0 to intDC0
Response.Write "<TR>"

'***************************************************************************
*********
'*** Loop to create spaces in front of Column headers
'*** to align with Row header
'***************************************************************************
*********
For c=0 to intDC1
Response.Write "<TD></TD>"
Next

'***************************************************************************
*********
'*** Iterate through Axes(0) Positions writing member captions to table
header
'***************************************************************************
*********
For i = 0 To intPC0
Response.Write "<TH>"
Response.Write "<FONT size=-2>"
Response.Write cst.Axes(0).Positions(i).Members(h).Caption
Response.Write "</FONT>"
Response.Write "</TH>"
Next
Response.Write "</TR>"
Next
'***************************************************************************
*********
'*** Use Array values for row header formatting to provide
'*** spaces under beginning row header titles
'***************************************************************************
*********
For j = 0 To intPC1
Response.Write "<TR>"
For h=0 to intDC1
Response.Write "<TD><B>"
Response.Write "<FONT size=-2>"
Response.Write cst.Axes(1).Positions(j).Members(h).Caption
Response.Write "</FONT>"
Response.Write "</B></TD>"
Next
For k = 0 To intPC0
Response.Write "<TD align=right bgcolor="
Response.Write csw
Response.Write ">"
Response.Write "<FONT size=-2>"
Response.Write cst(k, j).FormattedValue
Response.Write "</FONT>"
Response.Write "</TD>"
Next
Response.Write "</TR>"
Next
Response.Write "</Table>"

%>
</FONT>
</BODY>
</HTML>

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Elyo Ravuna" <[email protected]>
| Sender: "Elyo Ravuna" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: RE: Garbage collector has problems with ADO-MD interop
| Date: Mon, 20 Oct 2003 05:42:38 -0700
| Lines: 206
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOXB6S9adC/HNQsTHCu4A6sdKC9pw==
| Newsgroups: microsoft.public.dotnet.framework
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:56587
| NNTP-Posting-Host: TK2MSFTNGXS01 10.40.2.125
| X-Tomcat-NG: microsoft.public.dotnet.framework
|
| Hello Kevin,
|
| The exception does not appear inside Visual Studio.
| You have to build an EXE file, and run the EXE from the
| command prompt.
|
| Also, you have to make sure that "enable optimizations" is
| set in project properties. Otherwise, the exception does
| not appear.
|
| If you still cannot reproduce the problem, I will conclude
| that the problem is specific to our configuration.
|
| Thanks in advance,
| Elyo
|
| P.S.: The call that throws the exception
| is 'MyPosition.Members(0).UniqueName'.
|
|
| >-----Original Message-----
| >Hi Elyo,
| >
| >I cannot reproduce the error message "object is no longer
| valid" on my
| >computer. Can you tell me on which line was the exception
| thrown?
| >
| >Here are two KB articles which might be related with this
| issue. HTH.
| >
| >If anything is unclear, please feel free to reply to the
| post.
| >
| >Kevin Yu
| >=======
| >"This posting is provided "AS IS" with no warranties, and
| confers no
| >rights."
| >
| >--------------------
| >| Content-Class: urn:content-classes:message
| >| From: "Elyo Ravuna" <[email protected]>
| >| Sender: "Elyo Ravuna" <[email protected]>
| >| References: <[email protected]>
| ><[email protected]>
| >| Subject: RE: Garbage collector has problems with ADO-MD
| interop
| >| Date: Mon, 29 Sep 2003 00:37:09 -0700
| >| Lines: 125
| >| Message-ID: <[email protected]>
| >| MIME-Version: 1.0
| >| Content-Type: text/plain;
| >| charset="iso-8859-1"
| >| Content-Transfer-Encoding: 7bit
| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| Thread-Index: AcOGXH0mYbiGa7MsRladdJgbBhs71A==
| >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| >| Newsgroups: microsoft.public.dotnet.framework
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.framework:54940
| >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| >|
| >| We do NOT have any GC.Collect() in our original code.
| >|
| >| Users of our application started to get the
| >| message "object is no longer valid" randomly.
| >|
| >| Having an error message randomly made me think of the
| >| garbage collector, so I tried to put some GC.Collect()
| >| calls in the code in order to make the bug reproducible.
| >|
| >| GC.Collect() should not cause the code to fail.
| However,
| >| in our case:
| >|
| >| - Without GC.Collect() the code "sometimes" gives an
| error
| >| message.
| >| - With GC.Collect() the code "always" gives an error
| >| message.
| >|
| >| I isolated the problem in a very short program. I would
| be
| >| very glad if you could examine the code in my first
| >| message. The problem could be reproduced on any
| machine.
| >| (Our .net framework version is 1.1)
| >|
| >| Sincerely,
| >| Elyo Ravuna
| >|
| >|
| >| >-----Original Message-----
| >| >Hi Elyo,
| >| >
| >| >Both ADODB and ADOMD are unmanaged codes. Although
| they
| >| are running in VB
| >| >.NET, they're not created on managed heap. So, you
| cannot
| >| release them by
| >| >calling GC.Collect().
| >| >
| >| >Furthermore, garbage collection is managed by the .net
| >| framework. It will
| >| >be called automatically when there's not enough free
| >| memory. Please leave
| >| >it to the .net framework, or it might hit the
| performance
| >| of your
| >| >application.
| >| >
| >| >Does this answer your question? If anything is
| unclear,
| >| please feel free to
| >| >reply to the post.
| >| >
| >| >Kevin Yu
| >| >=======
| >| >"This posting is provided "AS IS" with no warranties,
| and
| >| confers no
| >| >rights."
| >| >
| >| >--------------------
| >| >| Content-Class: urn:content-classes:message
| >| >| From: "Elyo Ravuna" <[email protected]>
| >| >| Sender: "Elyo Ravuna" <[email protected]>
| >| >| Subject: Garbage collector has problems with ADO-MD
| >| interop
| >| >| Date: Fri, 26 Sep 2003 01:09:52 -0700
| >| >| Lines: 40
| >| >| Message-ID: <[email protected]>
| >| >| MIME-Version: 1.0
| >| >| Content-Type: text/plain;
| >| >| charset="iso-8859-1"
| >| >| Content-Transfer-Encoding: 7bit
| >| >| X-Newsreader: Microsoft CDO for Windows 2000
| >| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V5.50.4910.0300
| >| >| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| >| >| Newsgroups: microsoft.public.dotnet.framework
| >| >| Path: cpmsftngxa06.phx.gbl
| >| >| Xref: cpmsftngxa06.phx.gbl
| >| microsoft.public.dotnet.framework:54790
| >| >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| >| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| >| >|
| >| >| Our ADO-MD application sometimes gives the
| >| >| exception 'Object is no longer valid'.
| >| >|
| >| >| You can reproduce the problem using the following
| code.
| >| >|
| >| >| Module main
| >| >| 'When "enable optimizations" is set and the code is
| >| >| 'not run in the Visual Studio IDE, the following code
| >| >| 'gives the exception 'object is no longer valid'.
| >| >| 'The aim of GC.Collect() is to make the bug
| >| reproducible.
| >| >| Public Sub main()
| >| >| Try
| >| >| Dim MyConnection As New ADODB.Connection
| >| >| Dim MyCellset As New ADOMD.Cellset
| >| >| Dim MyPosition As ADOMD.Position
| >| >| Dim Dummy As String
| >| >| MyConnection.Open("provider=msolap;data
| >| >| source=localhost;initial catalog=Foodmart 2000")
| >| >| MyCellset.Open("select Time.Year.Members on 0
| >| from
| >| >| [Sales] where [Unit Sales]", MyConnection)
| >| >| For Each MyPosition In MyCellset.Axes
| (0).Positions
| >| >| GC.Collect() : GC.WaitForPendingFinalizers()
| >| >| Dummy = MyPosition.Members(0).UniqueName
| >| >| Next
| >| >| Catch ex As Exception
| >| >| MsgBox("Message:" + ex.Message + vbCrLf
| >| + "Source:"
| >| >| + ex.Source + vbCrLf + "StackTrace:" +
| >| >| ex.StackTrace, , "Exception")
| >| >| End Try
| >| >| End Sub
| >| >| End Module
| >| >|
| >| >|
| >| >| When I replace the for-each loop with an index loop,
| >| the
| >| >| code runs fine. Should I replace all for-each loops
| >| with
| >| >| index loops in our application?
| >| >|
| >| >| Sincerely,
| >| >| Elyo Ravuna
| >| >|
| >| >|
| >| >
| >| >.
| >| >
| >|
| >
| >.
| >
|
 
Hi Elyo,

I'd like to know if this issue has been resolved. If no, is there anything
that I can help? I'm still monitoring on it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| X-Tomcat-ID: 274060209
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: (e-mail address removed) (Kevin Yu [MSFT])
| Organization: Microsoft
| Date: Tue, 21 Oct 2003 11:28:00 GMT
| Subject: RE: Garbage collector has problems with ADO-MD interop
| X-Tomcat-NG: microsoft.public.dotnet.framework
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework
| Lines: 361
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:56675
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi Elyo,
|
| Please try to check which adodb library you're refering. There are two
| libraries in .net Add Reference dialog box. One is under .net tab, while
| the other is under COM tab. Try to remove the current reference to adodb,
| and add reference to the one under .net tab. Please refer to the
following
| article for more information:
|
| http://support.microsoft.com/default.aspx?scid=kb;en-us;318559
|
| I also found that you're using ADODB.Connection to connect to a OLAP
| service. It might work, however, I recommend you use ADOMD.Catalog to
| connect to it. The following is a code sample for your reference:
|
| <%@ Language=VBScript %>
| <%
|
'***************************************************************************
| *********
|
'***************************************************************************
| *********
| '*** Active Server Page displays OLAP data from default
| '*** MDX Query string and writes resulting cell set to HTML table
| '*** structure.
|
'***************************************************************************
| *********
|
'***************************************************************************
| *********
| Response.Buffer=True
| Response.Expires=0
| %>
| <HTML>
| <HEAD>
| <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
| </HEAD>
| <BODY bgcolor=Ivory>
| <FONT FACE=Verdana>
|
| <%
|
| Dim cat,cst,i,j,strSource,csw,intDC0,intDC1,intPC0, intPC1
|
|
'***************************************************************************
| *********
| '*** Set Connection Objects for Multi dimensional Catalog and Cell Set
|
'***************************************************************************
| *********
| Set cat = Server.CreateObject("ADOMD.Catalog")
| Set cst = Server.CreateObject("ADOMD.CellSet")
|
|
'***************************************************************************
| *********
| '*** Use default settings of a known OLAP Server
| '*** for Server Name for Connection Set Server Name Session Object
| '*** to default value
|
'***************************************************************************
| *********
|
'***************************************************************************
| *********
| '*** Must set OLAPServerName to OLAP Server that is
| '*** present on network
|
'***************************************************************************
| *********
| OLAPServerName = "Please set to present OLAP Server"
| cat.ActiveConnection = "Data Source=" & OLAPServerName & ";Initial
| Catalog=FoodMart;Provider=msolap;"
|
|
'***************************************************************************
| *********
| '*** Use default MDX Query string of a known query
| '*** that works with default server Set MDXQuery Session Object to
default
| value
|
'***************************************************************************
| *********
| strSource = strSource & "SELECT "
| strSource = strSource & "{[Measures].members} ON COLUMNS,"
| strSource = strSource & "NON EMPTY [Store].[Store City].members ON ROWS"
| strSource = strSource & " FROM Sales"
|
|
'***************************************************************************
| *********
| '*** Set Cell Set Source property to strSource to be passed on cell set
| open method
|
'***************************************************************************
| *********
| cst.Source = strSource
|
|
'***************************************************************************
| *********
| '*** Set Cell Sets Active connection to use the current Catalogs Active
| connection
|
'***************************************************************************
| *********
| Set cst.ActiveConnection = cat.ActiveConnection
|
|
'***************************************************************************
| *********
| '*** Using Open method, Open cell set
|
'***************************************************************************
| *********
| cst.Open
|
|
'***************************************************************************
| *********
| '*** Set Dimension Counts minus 1 for Both Axes to intDC0, intDC1
| '*** Set Position Counts minus 1 for Both Axes to intPC0, intPC1
|
'***************************************************************************
| *********
| intDC0 = cst.Axes(0).DimensionCount-1
| intDC1 = cst.Axes(1).DimensionCount-1
|
| intPC0 = cst.Axes(0).Positions.Count - 1
| intPC1 = cst.Axes(1).Positions.Count - 1
|
|
'***************************************************************************
| *********
| '*** Create HTML Table structure to hold MDX Query return Record set
|
'***************************************************************************
| *********
| Response.Write "<Table width=100% border=1>"
|
|
'***************************************************************************
| *********
| '*** Loop to create Column header
|
'***************************************************************************
| *********
| For h=0 to intDC0
| Response.Write "<TR>"
|
|
'***************************************************************************
| *********
| '*** Loop to create spaces in front of Column headers
| '*** to align with Row header
|
'***************************************************************************
| *********
| For c=0 to intDC1
| Response.Write "<TD></TD>"
| Next
|
|
'***************************************************************************
| *********
| '*** Iterate through Axes(0) Positions writing member captions to table
| header
|
'***************************************************************************
| *********
| For i = 0 To intPC0
| Response.Write "<TH>"
| Response.Write "<FONT size=-2>"
| Response.Write cst.Axes(0).Positions(i).Members(h).Caption
| Response.Write "</FONT>"
| Response.Write "</TH>"
| Next
| Response.Write "</TR>"
| Next
|
'***************************************************************************
| *********
| '*** Use Array values for row header formatting to provide
| '*** spaces under beginning row header titles
|
'***************************************************************************
| *********
| For j = 0 To intPC1
| Response.Write "<TR>"
| For h=0 to intDC1
| Response.Write "<TD><B>"
| Response.Write "<FONT size=-2>"
| Response.Write cst.Axes(1).Positions(j).Members(h).Caption
| Response.Write "</FONT>"
| Response.Write "</B></TD>"
| Next
| For k = 0 To intPC0
| Response.Write "<TD align=right bgcolor="
| Response.Write csw
| Response.Write ">"
| Response.Write "<FONT size=-2>"
| Response.Write cst(k, j).FormattedValue
| Response.Write "</FONT>"
| Response.Write "</TD>"
| Next
| Response.Write "</TR>"
| Next
| Response.Write "</Table>"
|
| %>
| </FONT>
| </BODY>
| </HTML>
|
| Kevin Yu
| =======
| "This posting is provided "AS IS" with no warranties, and confers no
| rights."
|
| --------------------
| | Content-Class: urn:content-classes:message
| | From: "Elyo Ravuna" <[email protected]>
| | Sender: "Elyo Ravuna" <[email protected]>
| | References: <[email protected]>
| <[email protected]>
| <[email protected]>
| <[email protected]>
| | Subject: RE: Garbage collector has problems with ADO-MD interop
| | Date: Mon, 20 Oct 2003 05:42:38 -0700
| | Lines: 206
| | Message-ID: <[email protected]>
| | MIME-Version: 1.0
| | Content-Type: text/plain;
| | charset="iso-8859-1"
| | Content-Transfer-Encoding: 7bit
| | X-Newsreader: Microsoft CDO for Windows 2000
| | X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| | Thread-Index: AcOXB6S9adC/HNQsTHCu4A6sdKC9pw==
| | Newsgroups: microsoft.public.dotnet.framework
| | Path: cpmsftngxa06.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:56587
| | NNTP-Posting-Host: TK2MSFTNGXS01 10.40.2.125
| | X-Tomcat-NG: microsoft.public.dotnet.framework
| |
| | Hello Kevin,
| |
| | The exception does not appear inside Visual Studio.
| | You have to build an EXE file, and run the EXE from the
| | command prompt.
| |
| | Also, you have to make sure that "enable optimizations" is
| | set in project properties. Otherwise, the exception does
| | not appear.
| |
| | If you still cannot reproduce the problem, I will conclude
| | that the problem is specific to our configuration.
| |
| | Thanks in advance,
| | Elyo
| |
| | P.S.: The call that throws the exception
| | is 'MyPosition.Members(0).UniqueName'.
| |
| |
| | >-----Original Message-----
| | >Hi Elyo,
| | >
| | >I cannot reproduce the error message "object is no longer
| | valid" on my
| | >computer. Can you tell me on which line was the exception
| | thrown?
| | >
| | >Here are two KB articles which might be related with this
| | issue. HTH.
| | >
| | >If anything is unclear, please feel free to reply to the
| | post.
| | >
| | >Kevin Yu
| | >=======
| | >"This posting is provided "AS IS" with no warranties, and
| | confers no
| | >rights."
| | >
| | >--------------------
| | >| Content-Class: urn:content-classes:message
| | >| From: "Elyo Ravuna" <[email protected]>
| | >| Sender: "Elyo Ravuna" <[email protected]>
| | >| References: <[email protected]>
| | ><[email protected]>
| | >| Subject: RE: Garbage collector has problems with ADO-MD
| | interop
| | >| Date: Mon, 29 Sep 2003 00:37:09 -0700
| | >| Lines: 125
| | >| Message-ID: <[email protected]>
| | >| MIME-Version: 1.0
| | >| Content-Type: text/plain;
| | >| charset="iso-8859-1"
| | >| Content-Transfer-Encoding: 7bit
| | >| X-Newsreader: Microsoft CDO for Windows 2000
| | >| Thread-Index: AcOGXH0mYbiGa7MsRladdJgbBhs71A==
| | >| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| | >| Newsgroups: microsoft.public.dotnet.framework
| | >| Path: cpmsftngxa06.phx.gbl
| | >| Xref: cpmsftngxa06.phx.gbl
| | microsoft.public.dotnet.framework:54940
| | >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| | >| X-Tomcat-NG: microsoft.public.dotnet.framework
| | >|
| | >| We do NOT have any GC.Collect() in our original code.
| | >|
| | >| Users of our application started to get the
| | >| message "object is no longer valid" randomly.
| | >|
| | >| Having an error message randomly made me think of the
| | >| garbage collector, so I tried to put some GC.Collect()
| | >| calls in the code in order to make the bug reproducible.
| | >|
| | >| GC.Collect() should not cause the code to fail.
| | However,
| | >| in our case:
| | >|
| | >| - Without GC.Collect() the code "sometimes" gives an
| | error
| | >| message.
| | >| - With GC.Collect() the code "always" gives an error
| | >| message.
| | >|
| | >| I isolated the problem in a very short program. I would
| | be
| | >| very glad if you could examine the code in my first
| | >| message. The problem could be reproduced on any
| | machine.
| | >| (Our .net framework version is 1.1)
| | >|
| | >| Sincerely,
| | >| Elyo Ravuna
| | >|
| | >|
| | >| >-----Original Message-----
| | >| >Hi Elyo,
| | >| >
| | >| >Both ADODB and ADOMD are unmanaged codes. Although
| | they
| | >| are running in VB
| | >| >.NET, they're not created on managed heap. So, you
| | cannot
| | >| release them by
| | >| >calling GC.Collect().
| | >| >
| | >| >Furthermore, garbage collection is managed by the .net
| | >| framework. It will
| | >| >be called automatically when there's not enough free
| | >| memory. Please leave
| | >| >it to the .net framework, or it might hit the
| | performance
| | >| of your
| | >| >application.
| | >| >
| | >| >Does this answer your question? If anything is
| | unclear,
| | >| please feel free to
| | >| >reply to the post.
| | >| >
| | >| >Kevin Yu
| | >| >=======
| | >| >"This posting is provided "AS IS" with no warranties,
| | and
| | >| confers no
| | >| >rights."
| | >| >
| | >| >--------------------
| | >| >| Content-Class: urn:content-classes:message
| | >| >| From: "Elyo Ravuna" <[email protected]>
| | >| >| Sender: "Elyo Ravuna" <[email protected]>
| | >| >| Subject: Garbage collector has problems with ADO-MD
| | >| interop
| | >| >| Date: Fri, 26 Sep 2003 01:09:52 -0700
| | >| >| Lines: 40
| | >| >| Message-ID: <[email protected]>
| | >| >| MIME-Version: 1.0
| | >| >| Content-Type: text/plain;
| | >| >| charset="iso-8859-1"
| | >| >| Content-Transfer-Encoding: 7bit
| | >| >| X-Newsreader: Microsoft CDO for Windows 2000
| | >| >| X-MimeOLE: Produced By Microsoft MimeOLE
| | V5.50.4910.0300
| | >| >| Thread-Index: AcOEBZAeSILbiiZCQDaxGuFkCz7HVw==
| | >| >| Newsgroups: microsoft.public.dotnet.framework
| | >| >| Path: cpmsftngxa06.phx.gbl
| | >| >| Xref: cpmsftngxa06.phx.gbl
| | >| microsoft.public.dotnet.framework:54790
| | >| >| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| | >| >| X-Tomcat-NG: microsoft.public.dotnet.framework
| | >| >|
| | >| >| Our ADO-MD application sometimes gives the
| | >| >| exception 'Object is no longer valid'.
| | >| >|
| | >| >| You can reproduce the problem using the following
| | code.
| | >| >|
| | >| >| Module main
| | >| >| 'When "enable optimizations" is set and the code is
| | >| >| 'not run in the Visual Studio IDE, the following code
| | >| >| 'gives the exception 'object is no longer valid'.
| | >| >| 'The aim of GC.Collect() is to make the bug
| | >| reproducible.
| | >| >| Public Sub main()
| | >| >| Try
| | >| >| Dim MyConnection As New ADODB.Connection
| | >| >| Dim MyCellset As New ADOMD.Cellset
| | >| >| Dim MyPosition As ADOMD.Position
| | >| >| Dim Dummy As String
| | >| >| MyConnection.Open("provider=msolap;data
| | >| >| source=localhost;initial catalog=Foodmart 2000")
| | >| >| MyCellset.Open("select Time.Year.Members on 0
| | >| from
| | >| >| [Sales] where [Unit Sales]", MyConnection)
| | >| >| For Each MyPosition In MyCellset.Axes
| | (0).Positions
| | >| >| GC.Collect() : GC.WaitForPendingFinalizers()
| | >| >| Dummy = MyPosition.Members(0).UniqueName
| | >| >| Next
| | >| >| Catch ex As Exception
| | >| >| MsgBox("Message:" + ex.Message + vbCrLf
| | >| + "Source:"
| | >| >| + ex.Source + vbCrLf + "StackTrace:" +
| | >| >| ex.StackTrace, , "Exception")
| | >| >| End Try
| | >| >| End Sub
| | >| >| End Module
| | >| >|
| | >| >|
| | >| >| When I replace the for-each loop with an index loop,
| | >| the
| | >| >| code runs fine. Should I replace all for-each loops
| | >| with
| | >| >| index loops in our application?
| | >| >|
| | >| >| Sincerely,
| | >| >| Elyo Ravuna
| | >| >|
| | >| >|
| | >| >
| | >| >.
| | >| >
| | >|
| | >
| | >.
| | >
| |
|
|
 
Back
Top