This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowThe Fabric community is upgrading! Read all of the details including the timeline and what you can expect. Learn more
Hi Folks,
I am trying to query data using Fabric SQL DB using python / pyspark. But I am not getting proper syntax to query. If anyone has , can someone share the syntax.
Thanks and regards.
Solved! Go to Solution.
Hi @chetanhiwale ,
You can query a Fabric SQL Database from a Spark notebook using JDBC. Here's a working example:
jdbc_url = "jdbc:sqlserver://<your-server>.database.fabric.microsoft.com:1433;database=<your-db>"
df = spark.read \
.format("jdbc") \
.option("url", jdbc_url) \
.option("dbtable", "dbo.YourTable") \
.option("authentication", "ActiveDirectoryInteractive") \
.load()
df.show()
Alternatively, if your SQL DB is in the same workspace, you can use the synapsesql connector:
df = spark.read.synapsesql("YourDatabase.dbo.YourTable")
Did this help?
Drop a kudo so others can find it !
😉
Hi @Tamanchu ,
I tried both both options but they are not working for me. Have you tried to use MS-SQL python module by Microsoft
Hi @chetanhiwale,
If the JDBC and synapsesql approaches didn't work, you can try using pyodbc directly in a Fabric notebook:
Also, could you share the error messages you got with the JDBC and synapsesql methods? That would help narrow down the root cause.
Thanks!
Hi @chetanhiwale ,
You can query a Fabric SQL Database from a Spark notebook using JDBC. Here's a working example:
jdbc_url = "jdbc:sqlserver://<your-server>.database.fabric.microsoft.com:1433;database=<your-db>"
df = spark.read \
.format("jdbc") \
.option("url", jdbc_url) \
.option("dbtable", "dbo.YourTable") \
.option("authentication", "ActiveDirectoryInteractive") \
.load()
df.show()
Alternatively, if your SQL DB is in the same workspace, you can use the synapsesql connector:
df = spark.read.synapsesql("YourDatabase.dbo.YourTable")
Did this help?
Drop a kudo so others can find it !
😉
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 4 | |
| 4 | |
| 3 |
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 5 |