cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Warehousing & Analytics
Engage in discussions on data warehousing, analytics, and BI solutions within the Databricks Community. Share insights, tips, and best practices for leveraging data for informed decision-making.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Does the ODBC driver for databricks support parameterized queries?

DilyanDimitrov
New Contributor

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? 

3 REPLIES 3

mjaptarro
New Contributor II

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.

mjaptarro
New Contributor II

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.

_Sumit_Kate
New Contributor II

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.

parameter.png

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group