LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Web Resources API Cannot Acess stored DB Refnum

Hi everyone,

I am using LabVIEW Web Resources APIs with SQL Server.

I open the DB connection in Startup VI and store the connection reference in a non-reentrant FGV.

However, when accessing the same DB reference from API VIs, I get NULL/invalid reference errors.

Has anyone faced this issue with Web Resources and shared DB references?

Also, what architecture or best practice do you recommend for handling persistent DB connections in LabVIEW REST APIs?

Thanks.

 

0 Kudos
Message 1 of 4
(261 Views)

That's expected behavior. The lifetime of LabVIEW refnums is tied to the lifetime of the top level VI in whose hierarchy the refnum was created. The Web Resource Vis are invoked by the NI web server dynamically which makes them factually being the top level VI for each call. And any refnum created inside that is then automatically garbage collected when they end and return control back to the webserver.

 

You have two solutions:

 

1) The easier one: pass the server connection information with the calls and open the connection each time or pass that connection information in your existing call and store it in your FGV instead of the refnum and reopen the connection each time.

Drawback: reopening the DB connection each time takes time and can slow down your queries considerably if the database is located remotely.

 

2) Create a deamon of some sorts as a LabVIEW executable that manages the connection. Start that deamon in your open() webmethod and pass it the connection parameters. It opens the connection and keeps running. Then pass the other webrequests to that deamon through VI Server or similar.

Drawback: More complicated and harder to test and debug.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 4
(249 Views)

Thank you for the detailed explanation.

I understand it better now. Even though both the database and the Web Resources application are running on the same local PC, the DB refnum lifetime is still tied to the top-level VI execution context. So once the Web Resource call completes, the underlying refnum becomes invalid even if it is stored in an FGV.

That explains the NULL/invalid reference behavior I was seeing...

Do you happen to have any sample project or code reference or recommended example for handling persistent database communication with LabVIEW Web Resources?

Appreciate your guidance...

0 Kudos
Message 3 of 4
(228 Views)

Unfortunately I do not have such an example. I used the LabVIEW Web Services quite some time ago, but that was for a library for a client who wanted to have a Web Service interface for their measurement device they sold. It did not involve any database interface and I do not have access to that software anymore as I do not work anymore in the company who did that project for the client. 

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 4 of 4
(209 Views)