LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL connection problem

Solved!
Go to solution

I'm making some database functions using CVI SQL toolkit 2.3 (on Windows 7 & LW/CVI 2013)

The sample files (weather, flowchart......) are all working.

I tried to create my own mdb file, but the table and data are directed to samples.mdb of the sample files.

I specified the path in DBCreateTableFromMap, but not successful.

 

Please advise.

 

 

0 Kudos
Message 1 of 5
(1,993 Views)

Hey Hong Kong,

 

A couple of questions and points:

 

  • Could you provide more background on what exactly you're trying to do, and how you're trying to accomplish it? i.e. provide a copy of your database and code.
  • DBCreateTableFromMap() takes an integer mapHandle as the first argument, and then a char tableName as the second argument. You shouldn't be passing any paths into this function as arguments
  • Can you connect to your custom database using the DBConnect() function? If the database is an OBDC data source, you can use the DSN flag. Refer to the 'connect.cws' example for this implementation (Help >> Find Examples >> search 'sql')

Bdog

 

 

 

 

0 Kudos
Message 2 of 5
(1,954 Views)

Hi,

 

We just want to make a custom database file.  All functions are working (DBConnect, DBBeginMap, DBMapColumnToxxxx, DBCreateTableFromMap......).

 

The only questions is, the data is automatically saved to sample.mdb (the sample file of CVI SQL toolkit under the folder C:\......\CVI\Samples\sql), instead of our target file. 

 

May be there are some settings in Windows ODBC but we have no idea.

 

Please advise.

0 Kudos
Message 3 of 5
(1,948 Views)

Hi Hong_Kong,

 

Thanks for providing that context. The first step is to register your database. I copy and pasted the default 'samples.mdb' file into another location and renamed it:

 

file.JPG

Now, we have to register the database in the Microsoft ODBC manager. For this, in my Windows search I searched for 'ODBC Data Source Administrator' and opened 'ODBC Data Sources (32-bit)'. I then navigate to the 'System DSN' tab.

 

system dsn.JPG

 

Here, we have our registered Data Source Names (DSN). The 'CVI SQL Samples' should look familiar because that's what CVI has been calling. To register our database, click on 'Add' and select the 'Microsoft Access Driver (*.mdb)' option:

 

new DSN.JPG

 

Click 'Finish', and enter a Name and Description as shown below. The Name is how you will reference this DB in CVI and any other code. 

 

new customdb.JPG

Click 'Create' and enter a name for your custom .mdb file. 

 

new customdbname.JPG

Click 'OK' and now you should see your database appear under the 'System Data Sources':

new sys data sources.JPG

Now just connect to it from your code by replacing "CVI SQL Samples" with "Custom DB":

 

new code.JPG

In your code specifically, you can replace the DB name in line 26 where you use CopyString().

 

Hope this helps,

Bdog

Message 4 of 5
(1,940 Views)
Solution
Accepted by Hong_Kong

Hi Bdog,

 

Got it!  Thank you so much.

 

A note for other users:

 

In Windows 7, the Administrative Tools shows only the 64-bit ODBC.  The 32-bit ODBC is located here:

  • The 32-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\SysWoW64 folder.
  • The 64-bit version of the Odbcad32.exe file is located in the %systemdrive%\Windows\System32 folder.

 

Message 5 of 5
(1,924 Views)