Shubham Saykar
Shubham Saykar

Reputation: 1

while I am connecting the my java application to azure sql database, I have to run the application twice

while I am connecting the my java application to azure sql database, I have to run the application twice . 1: while running the application I am able to create the database. it takes the database from the tenent.properties:- devTest=DbName

database.properties file:-

jdbc:sqlserver://XXXXXserver2.database.windows.net:1433;user=XXXX@XXXXserver2;password={your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;

2: while running the application second time my connection ulr looks like below and I'm getting connected to the database which is mention in the connection string

tenant. properties:- DevTest= DbName

database. properties file:-

jdbc:sqlserver://XXXXXserver2.database.windows.net:1433;database=DbName;user=XXXX@XXXXXserver2;password=your_password_here};encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;

Please help me out. Advance thank you!!!!!!!!!!!!!

Upvotes: 0

Views: 491

Answers (1)

AjayKumarGhose
AjayKumarGhose

Reputation: 4893

One of the workaround you can follow to resolve the above,

So basically you are not getting any error while connecting the azure sql database to java using JDBC driver for sql server . The difference only we can see is the db name is added after running twice.

Similar issue we had faced and after checking our internet connectivity and restarting the system able to connect when executing for the first time itself ,Suggest you to please try the same restart the application and system.

Few of the things need to ensure that you have added the following to your src/main/resources/application.properties

url=jdbc:sqlserver://$AZ_DATABASE_NAME.database.windows.net:1433;database=demo;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
user=demo@$AZ_DATABASE_NAME
password=$AZ_SQL_SERVER_PASSWORD
  • The above provided information to be apply for the sql server which you have created earlier before creating the java project.

For complete setup please refer this MICROSOFT DOCUMENTATION| Use Java and JDBC with Azure SQL Database

For more information please refer this MICROSOFT DOCUMENTATION| How to connect to Azure SQL with JDBC

Upvotes: 0

Related Questions