1
votes

I am able to connect to database which is having ip address,but if i have my database created in Azure SQL Database server in that i am not able to connect using spring configuration Java web application.It shows me error saying

The connection to the host vinayaka.cloudapp.net,555, named instance sqlexpress failed. Error: "java.net.UnknownHostException: vinayaka.cloudapp.net,555". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.

spring-config.xml

<bean id="dataSource"  
  class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
  <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />  
  <property name="url" value="jdbc:sqlserver://vinayaka.cloudapp.net,555\sqlexpress;database=Sample" />  
  <property name="username" value="user" />  
  <property name="password" value="pass" />    
 </bean> 

Note:

1) I am able to open and work on that server in SQL Server Management Studio.

2) If I am able to open in SQL Server Management Studio, it means my machine IP address is allowed by firewall.

3) I can connect to database created in Azure SQL Database.

Please give suggestion on this.

3
Can you provide the JDBC driver version number? Have you been able to successfully connect when using the following url?: jdbc:sqlserver://SERVERNAME.database.windows.net:1433;database=spring-boot-intr‌​o;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.wind‌​ows.net;loginTimeout=30;andrea-lam-MSFT

3 Answers

1
votes

The connection string of Azure SQL Database for JDBC is like jdbc:sqlserver://<hostname>.database.windows.net:1433;database=<dbname>;user=<user>@<hostname>;password={your_password_here};encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;.

You can check the connection string of your Azure SQL Database on Azure old portal or new portal, please see the pictures below.

Pic 1. Check the Connection String for JDBC on Azure old portal enter image description here

Pic 2. Check the Connection String for JDBC on Azure new portal enter image description here

0
votes

Is 555 the port, that is exposed by the database for connection? Shouldn't the connection string look like this?

<property name="url" value="jdbc:sqlserver://vinayaka.cloudapp.net:555\sqlexpress;database=Sample" />  

I have replaced , in your code with :

0
votes

Change your connection string like "jdbc:sqlserver://{HostName}.database.windows.net;database={databaseName};encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30". And use sqljdbc4 jar file. Hope it should work.