0

In tenant1 Azure Function, there is a Python function to connect to an Azure SQL database:

import aioodbc
import logging


async def create_db_connection(SERVER_NAME: str, DATABASE_NAME: str, USERNAME: str, PASSWORD: str) -> aioodbc.Connection: 
    CONNECTION_STRING = (
        'Driver={ODBC Driver 17 for SQL Server};'
        f'Server=tcp:{SERVER_NAME}.database.windows.net,1433;'
        f'Database={DATABASE_NAME};Uid={USERNAME};Pwd={PASSWORD};'
        'Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;'
    )
    conn = await retry(aioodbc.connect, dsn=CONNECTION_STRING, autocommit=True)
    logging.info(f'##### Azure SQL Server connection successfully created')
    return conn

Is it possible to use tenant2's SERVER_NAME, DATABASE_NAME, USERNAME and PASSWORD to connect to the database?

Or is there more to it than that?

SeaDude
  • 3,725
  • 6
  • 31
  • 68
  • What do you mean by tenant ? do you mean different Subscriptions ? – Mohit Ganorkar Feb 25 '23 at 03:05
  • Completely separate companies with different Azure AD tenants, definitely different Subscriptions. – SeaDude Feb 25 '23 at 07:09
  • 1
    Well then make sure to use connection string provided in the portal it should work . but I think the issue would be with firewall make sure to either whitelist the Ip addresses of function app listed in the networking tab or open up the sql server to all the trafic – Mohit Ganorkar Feb 25 '23 at 07:49

1 Answers1

0

If you need to access the applications like SQL Database from the different Azure Tenant, then your application should have access level to be multi-tenant configured.

  • Register the SQL database server in an App Registration.
  • Provide/Grant the Application Permissions such as Directory.ReadAll and Delegated Permissions.
  • User should be authenticated with that Application with the right permissions for accessing.

Refer to this MS Doc and SO1 for more information on accessing the multi-tenant configured applications.