#๐Ÿ”’ PySpark, JDBC and connecting to MSSQL Server

5 messages ยท Page 1 of 1 (latest)

elder path
#

hey! I'm trying to connect a SQL Server database with PySpark however I'm getting this error when it comes to 'load()'. I tried every advice that I saw on Stack Overflow but nothing worked for me. Is there anybody who has experienced this error before?

My code:

spark.read.format('jdbc')\
    .option('url','jdbc:sqlserver://[ip_address]:1433;database=Test;user=[username];password=[password];')\
    .option('driver', 'com.microsoft.sqlserver.jdbc.SQLServerDriver')\
    .option('dbtable', sqlQuery )\
    .load()\
    .show()

Error starts with:

Py4JJavaError                             Traceback (most recent call last)
Cell In[4], line 5
      1 spark.read.format('jdbc')\
      2     .option('url',sqlConnection)\
      3     .option('driver', 'com.microsoft.sqlserver.jdbc.SQLServerDriver')\
      4     .option('dbtable', sqlQuery )\
----> 5     .load()\
      6     .show()

The last error I can't handle: (I can connect to DB with this user by using SQL Server Management Studio, and I tried 3 different users.)

Py4JJavaError: An error occurred while calling o34.load.
: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user '[username]'. ClientConnectionId:b60537a5-bfbc-4e11-9d82-3
small trailBOT
#

@elder path

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

elder path
#

thanks, you guys replied my previous post but i couldn't reply again. (it was closed due to inactivity.)
@serene hornet , yes. i supplied username and password either in sql connection string and in spark.read.format... like

.option('username', [username])\
.option('password', [password])\

@dark scarab
when i try to use integratedSecurity, i encountered this error.

Py4JJavaError: An error occurred while calling o34.load.
: com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:b3ac1a08-afcc-42c2-8a39-6ed8f661e502
small trailBOT
#

@elder path

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.