From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Closing ADODB sub reference outs in VIs? (LV 8.5.1)

I had a question about closing references to items I have not explicitly opened.
 
e.g.
 
I create an ADODB connection object.
 
From that, I create an ADODB command object.
 
One of the Command properties is the Parameters reference. I do a parameters.Refresh and using count, I loop through a For loop getting Item references. For each Item reference, I get a parameter object.
 
One of the properties in the parameter object is a Properties reference.  I do a refresh on that and then go into another For loop. For each Item reference, I get a property node.
 
OK, now that I've gone through getting/setting information, I need to start working my way out. The last property node had an item reference out from the properties node. Should I close that? The properties node itself had as a reference out, should that be closed? The Parameter node has a reference out, should that be closed? Finally, the Parameters node has a reference out, should I close that?
 
The command and connection nodes I explicitly opened, so I know I need to close them. But these other references, should I be closing them, or do I only need to close the references I explicitly created?
 
Thanks, Bob
 
 
0 Kudos
Message 1 of 10
(4,073 Views)

Hi Bob,

Even if you use a property node to open a reference, it is still important to close all handles properly.  Closing ActiveX references frees up memory, so you can potentially test the necessity of closing each reference by putting the code in a while loop and seeing if the required memory increases over time.

Regards,

Lauren

Applications Engineering
National Instruments
0 Kudos
Message 2 of 10
(4,054 Views)

As mentioned, any reference should be closed, and in general, it's good practice to close each reference in the same place it was opened, so that you don't forget to close them.

For LabVIEW generated references, this actually matters less, because the compiler should be able to optimize those and release them automatically when they're no longer needed. For ActiveX references, however, you must do this yourself, because otherwise they will only be closed when the hierarchy goes idle. I suggest you read this for some more details. It talks about .NET, but I believe it should all apply to ActiveX as well.


___________________
Try to take over the world!
0 Kudos
Message 3 of 10
(4,040 Views)
Close everything.

Any reason you are making this yourself? It's been done in LabSQL. Or look
at it to study.

Regards,

Wiebe.


0 Kudos
Message 4 of 10
(3,993 Views)
I download LabSQL, it looks pretty close to what I want.
 
I'm looking for a VI that queries a stored procedure to determine what the parameters are, then creates a LabVIEW cluster with the correct datatypes. The idea is to call that first to create the Parameters object, then use it later, particularly for DML operations. (Say insert rows from a LV table.) I've tried using ADO recordsets to insert large datasets, and found it's performance to be lacking or unacceptable. I can insert several 1000 records per second with successive calls to a stored procedure where I specify ahead of time no result set.
 
If I really have lots of rows to insert, then I've found it better to prepare a file, move it to a place where the database can see it, and BULK INSERT it asynchronously and report the results back later.
 
Overall, I'm trying to create a LLB to distribute to other labVIEW programmers in my group to provide a consistent way to query databases I create. I want to do as much as possible via Stored Procedures, and create views on an application basis for more complex queries or apps that don't support stored procedures.
 
BTW, I liked the tip that any reference WIRE needs to be closed, that gives me a nice rule to know what I need to closed.
 
Bob
 
 
0 Kudos
Message 5 of 10
(3,975 Views)

"intp56" <x@no.email> wrote in message
news:1211895605937-713397@exchange.ni.com...
> I download LabSQL, it looks pretty close to what I want.
> &nbsp;

I'd suggest to use it, and to send them your additional code in return if
you're alowed to do that... Or suggest what you are missing to the project,
so they can add it in later versions.

> I'm looking for a VI that queries a stored procedure to determine what the
parameters are, then creates a LabVIEW cluster with the correct datatypes.
The idea is to call that first to create the Parameters object, then use it
later, particularly for DML operations. (Say insert rows from a LV table.)
I've tried using ADO recordsets to insert large datasets, and found it's
performance to be lacking or unacceptable. I can insert several 1000 records
per second with successive calls to a stored procedure where I specify ahead
of time no result set.

Not sure how ADO does this. I vaguely recall something about it. I think the
values are send item by item, and I think there was a faster way to send the
data by using a variant that directly accepts an array... It's been a while
since I've messed around with that, and I might not have succeeded to get it
working. Googling for "ADO large data sets" or something might give some
clues.

> If I really have lots of rows to insert, then I've found it better to
prepare a file, move it to a place where the database can see it, and BULK
INSERT it asynchronously and report the results back later.

Can't imagine that this is the best way to do it, but it's a good
workaround.

> BTW, I liked the tip that any reference WIRE needs to be closed, that
gives me a nice rule to know what I need to closed.

But even if there is no wire comming out of a reference property, you still
need to close it. So: every "green" read property should be closed.

Regards,

Wiebe.


0 Kudos
Message 6 of 10
(3,958 Views)


Wiebe@CARYA wrote:

But even if there is no wire comming out of a reference property, you still need to close it.

Not according to what Brian said in the post I linked to. He explicitly states that LabVIEW will automatically clean up references which are generated by property or invoke nodes but not put on wires.
 
Of course, He's refering to .NET. Do you know of anything different for ActiveX?

___________________
Try to take over the world!
0 Kudos
Message 7 of 10
(3,955 Views)
> Not according to what Brian said in the post I linked to. He explicitly
states that LabVIEW will automatically clean up references which are
generated by property or invoke nodes but not put on wires.
> &nbsp;
> Of course, He's refering to .NET. Do you know of anything different for
ActiveX?

Tst,

Can't see a link...

I've done a little test, and you/Brian seem to be right.

I've created a DOMDocument, and inserted one node. From this node, I read
the attribute reference. If I connect a wire to it, I get a leak. Withouth
the wire, no leak.

Did the test in LV7.1, so it should be the same or better in 8> versions.

Regards,

Wiebe.


0 Kudos
Message 8 of 10
(3,951 Views)
Here: http://detritus.blogs.com/lycangeek/2006/05/how_to_say_good.html

___________________
Try to take over the world!
0 Kudos
Message 9 of 10
(3,948 Views)
Tst,

Thanks. I've posted a comment to the article about the fact that everything
told in the artice also applies to ActiveX... Might be usefull to the
readers.

Regards,

Wiebe.


0 Kudos
Message 10 of 10
(3,929 Views)