Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric Data Days Monthly is back. Join us on March 26th for two expert-led sessions on 1) Getting Started with Fabric IQ and 2) Mapping & Spacial Analytics in Fabric. Register now

Reply
khanjaved
Microsoft Employee
Microsoft Employee

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.

khanjaved_0-1771346928981.png

 

Any recent change causing this issue?
 

Thanks

18 REPLIES 18
v-kpoloju-msft
Community Support
Community 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 1

Also, 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.

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.

@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?

Hi @khanjaved

Thank you for confirming that the session based %%tsql command also fails with the same SSL error.

In Microsoft Fabric, notebook connections to SQL Database use secure, platform-managed connectivity where authentication, encryption, and certificate validation are handled internally by the Fabric service. There are no tenant-level settings available to manually configure or override SSL certificate trust.

 

Since you have confirmed the same command works in another tenant but fails in this tenant even with newly created workspaces, SQL databases, and notebooks this helps isolate the behaviour to the tenant environment rather than notebook syntax or artifact configuration. In this case, it would be appropriate to engage your internal Microsoft support channel or create a support request so the Fabric team can further investigate the tenant-specific runtime and connectivity behaviour.

Thank you again for using the Microsoft Fabric Community Forum.

Hi @khanjaved

Just checking in to see if there has been any update on this issue after engaging the Microsoft support channel. Could you please confirm whether the issue has been resolved? If it is resolved, we would appreciate it if you could share the resolution or key insights here, as it may help other community members facing similar issues.

Thank you.

Hi @v-kpoloju-msft , I did not go to Microsoft support, Instead I tried using pyspark way and it wroked.

Hi @khanjaved

Thank you for the update. Glad to hear that the PySpark approach worked successfully. If you have any further questions please feel free to reach out to us. we will be happy to help.

Thank you for sharing your findings with the community.

AsgerLB
Resolver I
Resolver 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

Hi @AsgerLB , Tried both the way, still not working.

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-ma...
Br

Asger

@AsgerLBYes I tried, And I think with the session you can run the %tsql magic cmd in the next cell, alone with %%tsql look like its not going to be helpful.

@khanjaved , so you can make it work by using the -session parameter in one cell and then making your query in a new %%tsql command?

@AsgerLB How it will work? for session we need to use -artifact -type cmd which itself is not working for me now. which is the main issue I posted.

@khanjaved so running this 

 

%%tsql -artifact sqldb1 -type SQLDatabase -session
SELECT TOP (10) * FROM [SalesLT].[Address]

Does not work?

@AsgerLB  Yes not working.

@khanjaved  thanks for confirming.

I'm capable of querying my SQL database called TranslyticalDemo with a python notebook (ver 3.11) all placed in the same workspace via the following code:

%%tsql -artifact TranslyticalDemo -type SQLDatabase -session
SELECT * FROM [SalesLT].[Sales]

 

Can you confirm that you are using a Python execution engine for your notebook and which version, and that both items are in the same workspace?

Also what happens if you create a new python notebook in the workspace of your sqldb and run the code?

@AsgerLB Now I have created a new workspace, db and notebook on trial capacity, but still getting the same error.

@AsgerLB Fyi.. Tried one more thing, we have two tenant in other tenant its working fine, now need to see what need be fixed in the tenant where query is not working.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Fabric Update Carousel

Fabric Monthly Update - February 2026

Check out the February 2026 Fabric update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.