Forum Discussion

khanjaved's avatar
khanjaved
Microsoft Employee
6 months ago

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.

 

Any recent change causing this issue?
 

Thanks

18 Replies

  • 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 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.

    • v-kpoloju-msft's avatar
      v-kpoloju-msft
      Community 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.

      • khanjaved's avatar
        khanjaved
        Microsoft 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?