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. -
Module Module1
-
Sub Main()
-
Dim obj400Conn As New _
-
iSeries.iDB2Connection("DataSource=SOURCE;DefaultCollection=COLLECTION;userid=ID;password=PASS;")
-
-
Dim objAdapter As iSeries.iDB2DataAdapter
-
Dim objDataRowH, objDataRowD, objDBRow As DataRow
-
Dim objDSXML As New DataSet()
-
Dim objDSDBTable As New DataSet("F55FLFBP")
-
Dim ObjCmdBuilder As iSeries.iDB2CommandBuilder
-
-
For Each File As IO.FileInfo In New System.IO.DirectoryInfo("\\XMLDIR\").GetFiles
-
objDSXML.Tables.Clear()
-
objDSXML.ReadXml("\\XMLDIR\" & File.Name)
-
obj400Conn.Open()
-
-
objAdapter = New iSeries.iDB2DataAdapter("SELECT BP55FLTID, BPANI, BPTOTA, BP55FLSCAC, BP55FLVND#, BP55FLBOL, BP55FLFBN, BP55FLFBD, BPURCD FROM TSTDATA.F55FLFBP", obj400Conn)
-
objAdapter.Fill(objDSDBTable, "F55FLFBP")
-
Dim keyColumn(2) As DataColumn
-
keyColumn(0) = objDSDBTable.Tables(0).Columns("BP55FLTID")
-
keyColumn(1) = objDSDBTable.Tables(0).Columns("BPANI")
-
objDSDBTable.Tables(0).PrimaryKey = keyColumn
-
-
For Each objDataRowH In objDSXML.Tables(0).Rows
-
With objDSDBTable.Tables(0)
-
For Each objDataRowD In objDSXML.Tables(1).Rows
-
If objDataRowH(0) = objDataRowD(0) Then
-
objDBRow = .NewRow()
-
objDBRow(0) = objDataRowH(0)
-
objDBRow(1) = objDataRowD(1)
-
objDBRow(2) = objDataRowD(2) * 100
-
objDBRow(3) = objDataRowH(1)
-
objDBRow(4) = objDataRowH(2)
-
objDBRow(5) = objDataRowH(3)
-
objDBRow(6) = objDataRowH(4)
-
objDBRow(7) = objDataRowH(5)
-
objDBRow(8) = "N"
-
.Rows.Add(objDBRow)
-
End If
-
Next
-
End With
-
Next
-
-
ObjCmdBuilder = New iSeries.iDB2CommandBuilder(objAdapter)
-
objAdapter.Update(objDSDBTable, "F55FLFBP")
-
obj400Conn.Close()
-
-
'Move XML file from Processing DIR to Archive DIR
-
IO.File.Move("\\XMLDIR\" & File.Name, "\\XMLDIR\Archive\" & File.Name)
-
-
Next
-
End Sub
-
End Module
-
3 13378
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
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
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!
:)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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 -...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |