473,322 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Why disposing a object cause an error ?

Hi, everybody,

Error message is "COM object that has been separated from its underlying RCW
can not be used." When I called the codes below. So I traced the error and
found it is caused by "oCmd.Despose". BTW,these codes are included in a .net
component.

'-----------------------------------------------------------------
Dim odr As OleDbDataReader
Dim oCmd As New OleDbCommand

If Conn.State = ConnectionState.Closed Then Conn.Open()
With oCmd
.Connection = Conn
.CommandType = CommandType.StoredProcedure
.CommandText = "udpMySP"

.Parameters.Add(New OleDbParameter("", OleDbType.Integer))
.Parameters(0).Value = iID

End With

Try
odr = oCmd.ExecuteReader
Do While odr.Read()
'do something
Loop

Catch expOleDb As OleDbException
'handle error

Finally
If Conn.State <ConnectionState.Closed Then Conn.Close()

oCmd.Dispose()

If Not odr.IsClosed Then odr.Close()
End Try
'------------------------------------------------------------------

Thanks in advance,
Peter
Apr 9 '07 #1
1 1746
you shouldn't need to use .dispose

carry on

On Apr 8, 11:40 pm, "Peter" <zlxm...@sina.comwrote:
Hi, everybody,

Error message is "COM object that has been separated from its underlying RCW
can not be used." When I called the codes below. So I traced the error and
found it is caused by "oCmd.Despose". BTW,these codes are included in a .net
component.

'-----------------------------------------------------------------
Dim odr As OleDbDataReader
Dim oCmd As New OleDbCommand

If Conn.State = ConnectionState.Closed Then Conn.Open()
With oCmd
.Connection = Conn
.CommandType = CommandType.StoredProcedure
.CommandText = "udpMySP"

.Parameters.Add(New OleDbParameter("", OleDbType.Integer))
.Parameters(0).Value = iID

End With

Try
odr = oCmd.ExecuteReader
Do While odr.Read()
'do something
Loop

Catch expOleDb As OleDbException
'handle error

Finally
If Conn.State <ConnectionState.Closed Then Conn.Close()

oCmd.Dispose()

If Not odr.IsClosed Then odr.Close()
End Try
'------------------------------------------------------------------

Thanks in advance,
Peter

Apr 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kenneth Baltrinic | last post by:
I am getting the following error when deserializing an object that has a couple of dozen dependant objects in its object graph. Anyone who can suggest where I might begin to look to resolve problem...
0
by: faktujaa | last post by:
Hi, I receive the above error in my code when in debug mode but im not using serviced components instead im making use of sql server transaction. In short, I have defined a transaction class that...
4
by: MC D | last post by:
Question: If I have a class which has a property which is a collection of widget objects (an arrayList of widgets), and both the containter class and the widget class implement the IDisposable...
4
by: Dakkar | last post by:
I have a program with windows forms and after execution of my program im making it invisible for working background progress and i have a dispose function like this protected override void...
13
by: MuZZy | last post by:
Hi, Just wanted to make sure i get it right: consider this class: // =========== START CODE ============= class Test { private SqlConnection con = null; public void Connect() { con = new...
5
by: Chris | last post by:
I have a form that requires drawing custom lines on it. The color of the lines is suppose to be the same as the forcolor of the form. Am I doing this the most efficent and correct way? ...
0
by: Peter | last post by:
Hi, everybody, Error message is "COM object that has been separated from its underlying RCW can not be used." When I called the codes below. So I traced the error and found it is caused by...
21
by: phpCodeHead | last post by:
Code which should allow my constructor to accept arguments: <?php class Person { function __construct($name) { $this->name = $name; } function getName()
8
by: Varangian | last post by:
Hello, was wondering of how to dispose of managed resources? or referencing every member of a class to null will release resources...? http://www.marcclifton.com/tabid/79/Default.aspx...
29
by: Jerry Spence1 | last post by:
I'm rather confused as to whether something should be disposed of, or not. What is the general rule? How can you be sure of doing the right thing? I've heard about disposing unmanaged resources but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.