Forum Discussion
T‑SQL Magic Command (%%tsql) Error in Microsoft Fabric Notebook on Fabric SQL Database
Hello,
My T-SQL command executed from a Microsoft Fabric Python notebook against a Fabric SQL Database was working fine last week, but it has suddenly stopped working.
There is no change from our side.
Below is the similar syntax I am using:
%%tsql -artifact sqldb1 -type SQLDatabase
SELECT TOP (10) [AddressID]
,[AddressLine1]
,[AddressLine2]
,[City]
,[StateProvince]
,[CountryRegion]
,[PostalCode]
,[rowguid]
,[ModifiedDate]
FROM [SalesLT].[Address];
Ref doc : Run T-SQL code in Fabric Python notebooks - Microsoft Fabric | Microsoft Learn
Now getting error.
Thanks
18 Replies
- AsgerLBResolver I
Hi khanjaved
Thanks for your question.
It could be an issue with the latest release of the ODBC driver (18), which defaults to encryption making SSL/TLS mandatory and more pedantic about certificate details - you can try and run the following cell at the beginning of your notebook to explicitly tell your notebook envrionment to trust severside certificates:import os os.environ["ODBC_TRUST_SERVER_CERTIFICATE"] = "yes"Alternatively, try and see if you can replace the artifact 'nickname' with the fully qualified server name
%%tsql -artifact [FULL_SERVER_NAME] -type SQLDatabase SELECT TOP (10) * FROM [SalesLT].[Address];Br Asger
- AsgerLBResolver I
HI khanjaved thanks for getting back!
Have you tried adding the -session parameter along with your others? It seems like MS documentation specifies if you are using the tsql magic you must first establish a session connection:
https://learn.microsoft.com/en-us/fabric/data-engineering/tsql-magic-command-notebook#using-t-sql-magic-command-as-line-magic
Br
Asger
- v-kpoloju-msftCommunity Support
Hi khanjaved,
Thank you for testing across different workspaces, capacities, and even a new trial environment. Since the same %%tsql command works in another tenant but consistently fails in this tenant with the error "SSL Provider: certificate verify failed: self-signed certificate in certificate chain", this indicates the issue is not related to your notebook syntax or artifact usage. Instead, it points to a tenant-specific Fabric runtime or SQL Database connection trust configuration issue, where the notebook runtime is unable to validate the SQL Database certificate.
Please ensure the notebook is using the Python execution engine, restart the notebook session, and establish the connection using the session parameter as shown below:
%%tsql -artifact sqldb1 -type SQLDatabase -session SELECT 1Also, make sure the SQL Database and notebook are in the same workspace and the database artifact is properly attached to the notebook. If the issue still persists, since it works correctly in another tenant, this will most likely require tenant-level investigation by the Fabric engineering team, as the SSL trust validation is managed internally by the Fabric runtime environment rather than notebook code.
Hope this clarifies. Let us know if you have any doubts regarding this. We will be happy to help.
Thank you for using the Microsoft Fabric Community Forum.
- v-kpoloju-msftCommunity Support
Hi khanjaved,
Just checking in to see if the issue has been resolved on your end. If the earlier suggestions helped, that’s great to hear! And if you’re still facing challenges, feel free to share more details happy to assist further.Thank you.
- khanjavedMicrosoft Employee
v-kpoloju-msft I have alredy tried below cmd, this is also not working,
%%tsql -artifact sqldb1 -type SQLDatabase -session SELECT 1
For SSL trust validation, Is there any documentation what fabric or tenant team need to change?