LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading two tables in a SQL Database

Solved!
Go to solution

I am trying to using the Automatic SQL maps to read data from two tables in an SQL Database.

In Function One, I open a connect to the database,  map database columns to program variables, activate the map pointing to Table 1, fetch the records, deactivate the map, and close the database connection.

 

In Function Two, I open a connect to the database,  map database columns to program variables, activate the map pointing to Table 2, fetch the records, deactivate the map, and close the database connection.

 

They code is very similar. If I run Function One first, Function Two fails.  If I run Function Two first, Function One fails.  The error I get is

Database Error #-94.
Command was DBFetchNext(iMapHandle = 2).
Error Message = Invalid statement or connection handle.

 

I have try leaving the database connection open for both functions and still get the same error.  Even in with all this mess, I can still write data to a third table

 

Paul

 

0 Kudos
Message 1 of 4
(2,484 Views)

Hi Paul,

 

Can you post your code as well here? I think this might be helpful for debugging this.

 

Best,

Claire C.
AppSW Staff Product Support Engineer
National Instruments
CLD|CTD
0 Kudos
Message 2 of 4
(2,394 Views)

Claire,

 

It was Operator error.  I was stomping on the variable to the database connection, so the second function did not have a correct database connection.  Once I fixed the error, both functions work.

 

Paul

0 Kudos
Message 3 of 4
(2,383 Views)
Solution
Accepted by topic author paul.knight@astronics.com

Hi Paul,

 

Glad you were able to fix it! Best of luck on the rest of the project.

 

Best,

Claire C.
AppSW Staff Product Support Engineer
National Instruments
CLD|CTD
0 Kudos
Message 4 of 4
(2,381 Views)