Does the ODBC driver for databricks support parameterized queries?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2024 03:06 AM
Hi all,
I am using the official ODBC driver for databricks downloaded from here (the latest version) and trying to have a dotnet API (C#) fetching data from databricks via the driver. I am using the general Microsoft package for ODBC connection - System.Data.Odbc.
But it seems like when trying to execute a parameterized query I get the UNBOUND_SQL_PARAMETER error which says that the values for the params has not been passed.
Here is a snippet of my code:
using OdbcCommand command = connection.CreateCommand();
command.CommandText = Sql;
command.Parameters.Add(new OdbcParameter("param1", param1));
command.Parameters.Add(new OdbcParameter("param2", param2));
using OdbcDataReader reader = command.ExecuteReader();
and in the query I have :param1 and :param2.
I am wondering if the ODBC driver supports passing params to queries?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:56 PM
I'm getting the same error as well. I've even tried including the Driver in the connection string (on Windows it is Simba Spark ODBC Driver, and Linux has a similar name).
I've tried changing the param name :param1, @param1, and just param1. They all result in the same error.
Unfortunately you can't read or debug the ODBC driver.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 04:58 PM
I'll also point out that all of the chatGpt/copilots tell us our code is written correctly. Even the Assist in Data Bricks gives the same answer. I've read the docs and am unable to figure out an alternate way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2024 04:34 AM
Instead of named parameters, the ODBC .NET Provider uses positional parameters that are marked with a question mark (?) in the syntax of the command text.
Please make sure that UseNativeQuery to false(0) in the odbc connection string as they have mentioned in the https://docs.databricks.com/en/_extras/documents/Simba-Apache-Spark-ODBC-Connector-Install-and-Confi... . that when this option is enabled(1) the parameterized query won't work.

