Thanks for the question and using MS Q&A platform.
To access data from the dedicated SQL pool in Azure Synapse Notebook without exposing your password, you can store your database password securely in Azure Key Vault. To do this, you need to create an Azure Key Vault and then create a secret in the Key Vault with your database password.
Retrieve the secret value using below code:
from notebookutils import mssparkutils
mssparkutils.credentials.getSecret('AzureKeyvaultName', 'secretName')
Access dedicated sql database using below code:
from notebookutils import mssparkutils
jdbcHostname = "synpool.database.windows.net"
jdbcPort = 1433
jdbcDatabase = "dedsql"
jdbcUsername = "sqladminuser"
jdbcPassword = mssparkutils.credentials.getSecret('sqlservercred', 'sqlpassword')
jdbcDriver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
#url = s"jdbc:sqlserver://${database_host}:${database_port}/${database_name}"
table = "students"
jdbcUrl = f"jdbc:sqlserver://{jdbcHostname}:{jdbcPort};databaseName={jdbcDatabase}"
df1 = spark.read.format("jdbc").option("driver", jdbcDriver).option("url", jdbcUrl).option("dbtable", table).option("user", jdbcUsername).option("password", jdbcPassword).load()
df1.show()
Check this for adding access policies.
Hope this helps. Do let us know if you any further queries.
If this answers your query, do click Accept Answer
and Yes
for was this answer helpful. And, if you have any further query do let us know.