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

2024/9/30 15:25:57

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?

Answer

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.

https://en.xdnf.cn/q/71064.html

Related Q&A

Escape New line character in Spark CSV read

Im working on Spark 2.2.1 version and using the below python code, I can able to escape special characters like @ : I want to escape the special characters like newline(\n) and carriage return(\r). I r…

How can a class that inherits from a NumPy array change its own values?

I have a simple class that inherits from the NumPy n-dimensional array. I want to have two methods of the class that can change the array values of an instance of the class. One of the methods should s…

Python/SQL Alchemy Migrate - ValueError: too many values to unpack when migrating changes in db

I have several models in SQLAlchemy written and I just started getting an exception when running my migrate scripts: ValueError: too many values to unpackHere are my models:from app import dbROLE_USER …

How to store Dataframe data to Firebase Storage?

Given a pandas Dataframe which contains some data, what is the best to store this data to Firebase?Should I convert the Dataframe to a local file (e.g. .csv, .txt) and then upload it on Firebase Stora…

Multiple characters in Python ord function

Programming beginner here. (Python 2.7)Is there a work around for using more than a single character for Pythons ord function?For example, I have a hex string \xff\x1a which Id like the decimal value …

Get minimum x and y from 2D numpy array of points

Given a numpy 2D array of points, aka 3D array with size of the 3rd dimension equals to 2, how do I get the minimum x and y coordinate over all points? Examples:First:I edited my original example, sin…

Extract Text with its Font Details (Style,Size,color,Italic etc) from a PDF in Python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic…

How to keep track of status with multiprocessing and pool.map?

Im setting up a multiprocessing module for the first time, and basically, I am planning to do something along the lines offrom multiprocessing import pool pool = Pool(processes=102) results = pool.map(…

How to get time 17:00:00 today or yesterday?

If 17:00:00 today is already passed, then it should be todays date, otherwise - yesterdays. Todays time I get with:test = datetime.datetime.now().replace(hour=17,minute=0,second=0,microsecond=0)But I d…

PyMongo Aggregate how to get executionStats

I am trying to get executionStats of a Particular mongo aggregate query. I run db.command but that doesnt give "execution status"This is what I am trying to do. how to get Python Mongo Aggreg…