can't load data if I am not login into Azure SQL database

Renan 60 Reputation points
2024-12-05T11:09:24.0066667+00:00

I have created a job in Azure Databrick to transform data and load data into SQL database and schedule the time for it. If I am login into SQL database the code works fine and data is loaded into the database. However, if I am not login into SQL database I get this error:

“Py4JJavaError: An error occurred while calling o442.jdbc.

: com.microsoft.sqlserver.jdbc.SQLServerException: Database ' name of the database' on server 'name-of-server.database.windows.net' is not currently available. Please retry the connection later.”

The option “Allows Azure services and resources to access this server” is also ticked and saved.

 

Can you explain how to fix this problem? I need to be able to load the data into the database when I am not login. The code has all the credentials, but it only works when I actually manually has login into the SQL database and then run the code.

Confused...

 

Kind regards

Azure Databricks
Azure Databricks
An Apache Spark-based analytics platform optimized for Azure.
2,514 questions
{count} votes

1 answer

Sort by: Most helpful
  1. phemanth 15,755 Reputation points Microsoft External Staff Moderator
    2024-12-05T21:03:45.75+00:00

    Hi@Renan

    Thanks for reaching out to Microsoft Q&A.

    The error you’re seeing suggests that the database might not be accessible due to transient connectivity issues or configuration settings. Here are steps to troubleshoot and resolve this:

    1. Check Firewall Rules: Ensure that your IP address is allowed to access the Azure SQL Database. You can add your IP address to the firewall rules in the Azure portal under the SQL Database settings.
    2. Service Principal Authentication: Instead of using your personal login, consider using a service principal for authentication. This way, your Databricks job can authenticate without needing you to be logged in. You can set up a service principal in Azure Active Directory and grant it access to your SQL Database.
    3. Retry Logic: Implement retry logic in your code to handle transient errors. Azure SQL Database can sometimes have brief periods of unavailability due to maintenance or load balancing. Adding retry logic can help your application handle these temporary issues gracefully.
    4. Connection String: Ensure your connection string is correctly configured with all necessary parameters, including the correct server name, database name, and authentication details.

    If you’re frequently prompted to add a new IP address, it might be due to dynamic IP changes from your ISP. Here are some solutions:

    1. Use a Static IP: If possible, use a static IP address for your connection. This will prevent the need to update the firewall rules frequently.
    2. VPN or Azure Bastion: Consider using a VPN or Azure Bastion to connect to your Azure SQL Database. This can provide a consistent IP address for your connections.
    3. Allow Azure Services: Ensure that the option to allow Azure services and resources to access your server is enabled. This setting can help if your Databricks job is running within Azure.

    Please check the below reference for more details

    Troubleshoot common connection issues - Azure SQL Database & Azure SQL Managed Instance

    I hope the above steps will resolve the issue, please do let us know if issue persists. Thank you

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.