Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify the driver dll directly in the ODBC connection string?

I'm trying to use pyodbc to connect to a SQL Server (MS SQL Server through FreeTDS) in a portable application; since it's supposed to be standalone, I would like to avoid having to explicitly install the driver on the system, just bringing the ODBC driver dll along the application.

This page suggests that it's possible to specify the driver dll directly in the connection string

  • Specify the DRIVER= parameter in the szConnStrIn argument to the SQLDriverConnect function. For example:

    szConnStrIn = "driver=ospath/dbodbc6.dll;dbf=c:\asademo.db"
    

    where ospath is the operating system subdirectory of your Adaptive Server Anywhere installation directory.

Trying it through pyodbc+libtdsodbc.so on Linux, it does work fine; however, trying the same on Windows (pyodbc+tdsodbc.dll) I always get

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

(my libtdsodbc.so seems to be fine, though, since, if I install it as a "regular" driver and refer it with its name it connects fine)

Checking the documentation of SQLDriverConnect and related pages there's no mention of the DRIVER= option used straight with the dll path.

So, isn't "straight-to-driver-dll" connection not supported on Windows? Are there any alternatives, especially with Python, to connect straight to the driver dll, bypassing the ODBC driver manager?

like image 249
Matteo Italia Avatar asked Oct 26 '16 13:10

Matteo Italia


People also ask

What is connection string in ODBC?

String. The ODBC driver connection string that includes settings, such as the data source name, needed to establish the initial connection. The default value is an empty string (""). The maximum length is 1024 characters.


1 Answers

Like the answer by TallTed mentions, the documentation you linked contains quite a bit of information (but maybe it was not there at the time), and it is also explicit on the meaning of the driver parameter:

Description of the driver as returned by the SQLDrivers function. For example, Rdb or SQL Server.

It follows that it is not valid to indicate a path there in Windows (with the default ODBC implementation at least).

It also does not seem to be possible in general to use an ODBC driver without registering it, which requires admin rights. This answer lists some options.

like image 102
LCC Avatar answered Oct 19 '22 00:10

LCC