Reputation: 126907
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 theszConnStrIn
argument to theSQLDriverConnect
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?
Upvotes: 7
Views: 3211
Reputation: 948
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.
Upvotes: 1
Reputation: 9444
It's likely impossible to troubleshoot this now, 2.5 years later, but my best guess would be a typo or permissions error on the unregistered libtdsodbc.so
, or some other error in your SQLDriverConnect()
call (which you did not provide, so cannot be analyzed).
I think you must not have read the documentation of SQLDriverConnect()
carefully or completely, as it explicitly includes DRIVER
in the EBNF of SQLDriverConnect()
--
empty-string ::=attribute ::= attribute-keyword=attribute-value | DRIVER=[{]attribute-value[}]
-- and discusses it further in the details of the "Comments" section.
Note that this does not "bypass the ODBC driver manager," though it does make a DSN-less connection (so does not refer to the odbc.ini
Registry trees on Windows, nor the odbc.ini
file(s) on other OS).
Upvotes: 0