ODBC Connect
There are two different ways to pass UID and PWD:
By using the ODBC connection string:
_odbc.connect("DSN=MyDSN;UID=MyUser;PWD=MyPassword");
or, by using the DSN file:
_odbc.connect("FILEDSN=C:\\MyPath\\FILEDSN.dsn"); //Example of FILEDSN.dsn content: [ODBC] DRIVER=SQL ServerSERVER=localhost DATABASE=DODB UID=MyUser PWD=MyPassword
Please be aware that storing passwords in plain text within script or DSN files is insecure! A more secure approach is to use environment variables and retrieve the credentials via the script.
User name and password can be passed via the ODBC connection string. According to the SQLDriverConnect Function Specification the following connection string parameters are supported:
Keyword | Attribute value description |
---|---|
DSN | Name of a data source as returned by SQLDataSources or the data sources dialog box of SQLDriverConnect. |
FILEDSN | Name of a .dsn file from which a connection string will be built for the data source. These data sources are called file data sources. |
DRIVER | Description of the driver as returned by the SQLDrivers function. For example, Rdb or SQL Server. |
UID | A user ID. |
PWD | The password corresponding to the user ID, or an empty string if there is no password for the user ID (PWD=;). |
SAVEFILE | The file name of a .dsn file in which the attribute values of keywords used in making the present, successful connection should be saved. |
If any keywords are repeated in the connection string, the driver uses the value associated with the first occurrence of the keyword. If the DSN and DRIVER keywords are included in the same connection string, the Driver Manager and the driver use whichever keyword appears first.
The FILEDSN and DSN keywords are mutually exclusive: whichever keyword appears first is used, and the one that appears second is ignored. The FILEDSN and DRIVER keywords, on the other hand, are not mutually exclusive. If any keyword appears in a connection string with FILEDSN, then the attribute value of the keyword in the connection string is used rather than the attribute value of the same keyword in the .dsn file.