473,399 Members | 4,177 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,399 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 1751
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.