Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
3 rating:
 1.66 out of 5     Rate this Document

Programmatically Specifying an Arbitrary File as the Data Source with the CVI-SQL Toolkit

Primary Software: LabWindows/CVI Add-ons>>Enterprise Connectivity Toolset
Primary Software Version: 1.1
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: How do I specify a particular file at run-time to be used as the data source for the DBConnect function?


Solution: There are two fields that are essential when opening a connection to a file. These fields are specified in the connection string of the DBConnect function:

DBConnect(ConnectionString);

The required fields are DRIVER and DBQ.

To connect to an excel spreadsheet for example, the connectString would be:

"DRIVER=Microsoft Excel Driver (*.xls);DBQ=C:\\MyExcelFile.xls"

It is possible to specify other parameters in the connect string. The easiest way to find these parameters is to create a File DSN in the ODBC administrator for a file of the correct type (e.g., *.xls) and then open the created DSN file in a text editor. Each line in the ODBC section is a parameter that can be used in the connection string. For example, the following is the File DSN that was generated for the file c:\MyExcelFile.xls:

[ODBC]
DRIVER=Microsoft Excel Driver (*.xls)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
ReadOnly=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=excel 8.0
DriverId=790
DefaultDir=C:\
DBQ=C:\MyExcelFile.xls

To specify this same information in DBConnect, set the connectString to be:

connectString = "DRIVER=Microsoft Excel Driver (*.xls);UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;ReadOnly=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL=excel 8.0;DriverId=790;DefaultDir=C:\\;DBQ=C:\\MyExcelFile.xls"

The two fields or parameters that are essential are DRIVERand DBQ, so the pared down connect string is:

connectString = "DRIVER=Microsoft Excel Driver (*.xls);DBQ=C:\\MyExcelFile.xls"

Please note the use of semicolons to separate the parameters in the list and the use of double \\ in all of the paths.


If you are only using the drivers that ship with the CVI SQL Toolkit, then please consult the documentation (help files) for the specific fields allowed. For the Intersolv DataDirect Connect ODBC for Excel Workbook driver that ships with the SQL toolkit, the following is the connect string to use:

connectString = "DRIVER=CVI SQL 2.0 ExcelWorkbook (*.xls);DB=C:\\MyExcelFile.xls"


Related Links: KnowledgeBase 2BOEMOEV: Why Do I Get "Native error code message" When I Call A LabWindows/CVI SQL Toolkit Function In My Program?
KnowledgeBase 1YKI602L: Which SQL Functions Can I Use with the LabWindows/CVI SQL Toolkit 2.0?
KnowledgeBase 2QDEBL6I: Why Do I Get Error -2147352573 When I Run SQL Toolkit 2.0 Examples for LabWindows/CVI Version 6.0?


Attachments:





Report Date: 05/27/1999
Last Updated: 12/06/2004
Document ID: 1LQ7KVUT

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit