cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Server Connection on LTS 14.3

fk5
New Contributor II

Hi, what is the best way to connect to a SQL Server on LTS 14.3?

I've been trying to setup a connection to an SQL Server as referenced here. However both using both "sqlserver" and "jdbc" as format has resulted in an exception when using display as spark will send a LIMIT clause to the SQL Server. Reading the data and counting seems to work fine. 

df_jdbc = (spark.read.format('jdbc') \
            .option('driver', 'com.microsoft.sqlserver.jdbc.SQLServerDriver') \
            .option('url', jdbc_url) \
            .option('user', sql_server_user) \
            .option('password', sql_server_password) \
            .option("dbtable", 'dbo.TestTable') \
            .load())

df_jdbc.display()
# com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '10001'.

df = (spark.read.format('sqlserver') \
            .option('host', sql_server_host) \
            .option('port', sql_server_port) \
            .option('database', sql_server_database) \
            .option('user', sql_server_user) \
            .option('password', sql_server_password) \
            .option("dbtable", 'dbo.TestTable')
            .load())

df.display()
# com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near '10001'.

# Query send by spark in both queries: SELECT TestColumn FROM dbo.TestTable     LIMIT 10001 

 

3 REPLIES 3

szymon_dybczak
Contributor III

Bit weird, I've tested option with format('sqlserver') and I didn't notice any problems on LTS 14.3. Did you check what happens if you use databricks specific display command, like so:

display(df)




Slash_0-1720089847300.png

 

fk5
New Contributor II

In this instance neither df.display() or display(df) does work because in the end both will return the same sql to SQL Server. However I noticed it seems to be an error in the config of our cluster as it does work fine on a new compute. 

Probably has to do with the custom dialect we are using to map TimestampType to datetime2. 

Cool, I'm glad that you were able to pinpoint the issue.

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