473,386 Members | 1,712 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,386 software developers and data experts.

Getting Error: ObjectDisposedException was unhandled...Safe handle has been closed

Hi everyone, first post here AND new to VB.NET .. So please excuse any goofs that follow!

I have written a simple console application that extracts data from multiple XML files and inserts the data into a table which resides on our AS/400. All of the code appears to be working correctly and all the data which I expect from the XML files does end up in the table on the 400 ... But when the project is finishing/closing, I get this error thrown at me: ObjectDisposedException was unhandled ... Safe handle has been closed

I am on .NET 2005 on an XP machine. Below is the code that I am using (Also, I am SURE that there are BETTER ways to go about doing what I'm doing ... But hey, I'm learning here!!!). If there is more information needed from me, just let me know ... And thanks in advance for any help on this.

Expand|Select|Wrap|Line Numbers
  1. Module Module1
  2.     Sub Main()
  3.         Dim obj400Conn As New _
  4.         iSeries.iDB2Connection("DataSource=SOURCE;DefaultCollection=COLLECTION;userid=ID;password=PASS;")
  5.  
  6.         Dim objAdapter As iSeries.iDB2DataAdapter
  7.         Dim objDataRowH, objDataRowD, objDBRow As DataRow
  8.         Dim objDSXML As New DataSet()
  9.         Dim objDSDBTable As New DataSet("F55FLFBP")
  10.         Dim ObjCmdBuilder As iSeries.iDB2CommandBuilder
  11.  
  12.         For Each File As IO.FileInfo In New System.IO.DirectoryInfo("\\XMLDIR\").GetFiles
  13.             objDSXML.Tables.Clear()
  14.             objDSXML.ReadXml("\\XMLDIR\" & File.Name)
  15.             obj400Conn.Open()
  16.  
  17.             objAdapter = New iSeries.iDB2DataAdapter("SELECT BP55FLTID, BPANI, BPTOTA, BP55FLSCAC, BP55FLVND#, BP55FLBOL, BP55FLFBN, BP55FLFBD, BPURCD FROM TSTDATA.F55FLFBP", obj400Conn)
  18.             objAdapter.Fill(objDSDBTable, "F55FLFBP")
  19.             Dim keyColumn(2) As DataColumn
  20.             keyColumn(0) = objDSDBTable.Tables(0).Columns("BP55FLTID")
  21.             keyColumn(1) = objDSDBTable.Tables(0).Columns("BPANI")
  22.             objDSDBTable.Tables(0).PrimaryKey = keyColumn
  23.  
  24.             For Each objDataRowH In objDSXML.Tables(0).Rows
  25.                 With objDSDBTable.Tables(0)
  26.                     For Each objDataRowD In objDSXML.Tables(1).Rows
  27.                         If objDataRowH(0) = objDataRowD(0) Then
  28.                             objDBRow = .NewRow()
  29.                             objDBRow(0) = objDataRowH(0)
  30.                             objDBRow(1) = objDataRowD(1)
  31.                             objDBRow(2) = objDataRowD(2) * 100
  32.                             objDBRow(3) = objDataRowH(1)
  33.                             objDBRow(4) = objDataRowH(2)
  34.                             objDBRow(5) = objDataRowH(3)
  35.                             objDBRow(6) = objDataRowH(4)
  36.                             objDBRow(7) = objDataRowH(5)
  37.                             objDBRow(8) = "N"
  38.                             .Rows.Add(objDBRow)
  39.                         End If
  40.                     Next
  41.                 End With
  42.             Next
  43.  
  44.             ObjCmdBuilder = New iSeries.iDB2CommandBuilder(objAdapter)
  45.             objAdapter.Update(objDSDBTable, "F55FLFBP")
  46.             obj400Conn.Close()
  47.  
  48.             'Move XML file from Processing DIR to Archive DIR
  49.             IO.File.Move("\\XMLDIR\" & File.Name, "\\XMLDIR\Archive\" & File.Name)
  50.  
  51.         Next
  52. End Sub
  53. End Module
  54.  
May 1 '07 #1
3 13378
Frinavale
9,735 Expert Mod 8TB
Hi everyone, first post here AND new to VB.NET .. So please excuse any goofs that follow!

I have written a simple console application that extracts data from multiple XML files and inserts the data into a table which resides on our AS/400. All of the code appears to be working correctly and all the data which I expect from the XML files does end up in the table on the 400 ... But when the project is finishing/closing, I get this error thrown at me: ObjectDisposedException was unhandled ... Safe handle has been closed

I am on .NET 2005 on an XP machine. Below is the code that I am using (Also, I am SURE that there are BETTER ways to go about doing what I'm doing ... But hey, I'm learning here!!!). If there is more information needed from me, just let me know ... And thanks in advance for any help on this.
...

If you recreate a resource many times the deconstructor for that object isn't called to dispose of any of the resources no longer being used or referenced. This is why we normally call the Dispose() function whenever we're done using a resource like a database connection.

If you create an object on the managed heap that allocates resources such as handlers or connections, then you must ensure that the object has released its resources before allowing the garbage collection to recycle the object.

It sounds like you are letting the garbage collector recycle objects that are used by other resources. It could be your database handers or even your file reference resources.

I'd look at your code a little more but I don't have time right now so I'll leave you with thinking about manually managing when objects are disposed of.

I recommend looking up the IDisposable interface.
Check out this link to find out why this is so important. It might also shed some light on your error.

Cheers!

-Frinny
May 1 '07 #2
Thanks much for the reply back Frinavale! I read through the article, trying to expand my .NET knowhow a bit more (I found most of it a bit of it over my head unfortunatley...I have been working with VB & .NET for only a couple weeks).

Anywho, I have gotten to the source of my error (Or so I think for now). I did not have the latest Service Pack (SI26879) installed for my IBM Client Access version (V5R4M0). Once I installed the service pack, the error was gone with no modification done to the code.

-Shad3JD
May 2 '07 #3
Frinavale
9,735 Expert Mod 8TB
Thanks much for the reply back Frinavale! I read through the article, trying to expand my .NET knowhow a bit more (I found most of it a bit of it over my head unfortunatley...I have been working with VB & .NET for only a couple weeks).

Anywho, I have gotten to the source of my error (Or so I think for now). I did not have the latest Service Pack (SI26879) installed for my IBM Client Access version (V5R4M0). Once I installed the service pack, the error was gone with no modification done to the code.

-Shad3JD

Congratz Shad3JD!

:)
May 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: amber | last post by:
Hello, I have a parent form, with a menu item used to open the child form. If I open the child form, then close it, and try to reopen it from the parent, I get the error message: An unhandled...
0
by: jack | last post by:
I have written a fairly simple c# server that uses asynchronous sockets. I have two different clients that connect and send/receive info from the server. Both exihibit this behaviour where...
6
by: Paul | last post by:
Hello, The following code generates an exception error the *second* time it is called. Can anyone see what I'm doing wrong? There is a similar example in Wrox Professional VB.NET Page 289. ...
2
by: KJAbbott | last post by:
I have developed an application in VS 2005 for the Compact Framework. This application makes asynchronous web service calls on a timer. If the application is closed at a random time it will throw...
11
by: hazz | last post by:
smtpClient.Send(message) is causing me problems as per specifics in the trace below. Email is sent but not without this error typically upon sending the second email, but sometimes when running...
3
by: Larry Herbinaux | last post by:
I have built an asychronous TCP Server that uses the thread pool. I have two levels of exception handling in case the handling of the inner catch block throws an exception. The outer catch block...
5
by: kimtherkelsen | last post by:
Hi, I have made some software that uses one of the COM ports to communicate with an external device. The software is written in C# and uses the new SerialPort class in .Net 2.0. It works...
6
by: J055 | last post by:
Hi I have the following code. I upload an XML file using the FileUpload object, store the stream in a session so the user gets the chance to confirm some options then pass the stream from the...
4
by: Bernard Borsu | last post by:
Hi ! I have a big problem with a asp.net 2.0 website. I've just upgrade it from asp.net 1.1. In this previous version, no problem at all. Now, i've a recursive error .NET Runtime 2.0 Error -...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.