ODBCConfigureData
(Engine-Level Function)
Description: | Configures an ODBC data source and returns its error code. |
Returns: | Numeric |
Usage: | Script Only. |
Function Groups: | Database and Data Source, ODBC |
Related to: | ODBC | ODBCConnect | ODBCDisconnect | ODBCSources | ODBCStatus | ODBCTables | TODBC | TODBCConnect | TODBCDisconnect |
Format: | ODBCConfigureData(Mode, DriverName [, Settings]) |
Parameters: |
Mode | ||||||||
Required. Any numeric expression for the mode as follows:
In order for 64-bit VTScada to work with 64-bit data sources, add 64 to the Mode parameter. 32-bit VTScada cannot configure a 64-bit data source. |
DriverName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. Any text expression for the ODBC driver name, as configured in the ODBC setup menu under Microsoft Windows™. In the case of Excel, use "Microsoft Excel Driver (*.xls)". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A variety of optional parameters that are text expressions, giving the variable and value pairs used to specify the configuration of the ODBC data source. Any number of these parameter pairs may be used by simply listing the text string containing the variable name, followed by the value that the variable is to be set to. The variables to use include
If the DriverID option was selected, the Excel driver values that may be used are as follows:
Microsoft SQL Server requires additional keyword-value pairs. It uses the keywords in the following table. Note that only the SERVER keyword is required for this function. All other keywords are optional.
|
Comments: | If the data source already exists, it will be reconfigured as per the specs given and "0" (no error) will be returned. The data source name may not contain apostrophes or an ODBC error will occur. The function will return the error code. Some types of ODBC data sources, such as Microsoft™ Excel, do not require the file to be created prior to executing SQL commands on the data source, but will create a blank file when the first SQL Create Table command is executed. Others, such as Microsoft™ Access require the file to be created prior to execution of any SQL statements. Please note that configuration of ODBC Data Sources requires write permission to the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI". If the current user doesn't have write permission to the key, then the string "Insufficient permissions" will be returned. This means that VTScada must be run as Administrator for the function to work. The following table identifies some possible errors and their meaning:
|
Examples:
{ Create a data source } If ZButton(10, 30, 110, 10, "Create DS", 1); [ { Make sure name doesn't contain apostrophes } Replace(DSName, 0, StrLen(DSName), "'", ""); ODBCConfigureData(0, "Microsoft Access Driver (*.mdb)", "DSN", DSName, "DefaultDir", Concat(DSDrive, DSPath), "DBQ", Concat(DSFileName, ".MDB"), "Description", DSDesc, "FileType", "Access", "ReadOnly", 0); ] { Create the data source's file } If ZButton(10, 70, 110, 40, "Create file", 2); [ ODBCConfigureData(1, "Microsoft Access Driver (*.mdb)", "DSN", DSName, "CREATE_DB", Concat(DSDrive, DSPath, DSFileName, ".MDB")); ] { Delete the data source } If ZButton(10, 110, 110, 80, "Delete DS", 3); [ ODBCConfigureData(2, "Microsoft Access Driver (*.mdb)", "DSN", DSName); ] { Create a MS SQL Server data source } If ZButton(10, 150, 110, 120, "Create SQL DS", 3); [ ErrorCode = ODBCConfigureData(0, "SQL Server", "DSN",ODBCName, "Description", "SQL server connection created by VTS.", "SERVER", ComputerName, "NETWORK", "DBMSSOCN" ); ]
To remove a 64-bit data source (using 64-bit VTS):
ODBCConfigureData(66, …)
To add a 32-bit data source (using either 64-bit or 32-bit VTS):
ODBCConfigureData(0, …)