1

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.

1
  • 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; Commented Feb 9, 2016 at 19:17

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

i have mentioned in note of that "I can connect to database created in sql database in Azure" .In this there will be other tab called server along with next to sql database tab.in that i have my server inside that i have a database.Yes to this server i am not able to connect.
@dafodil Hi, I think there are two cases. 1. You need to use the sqlserver jdbc driver version later than 4.0. 2. You need allow the client ip in the firewall rules, operate at the Manage allowed IP addresses.
0

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 :

3 Comments

I had also tried with this .it gives me Could not open connection and The port number 555\sqlexpress is not valid. error
Is your database port open for the incoming connections in the firewall?
Yes,the same sql server is being used in other platform(asp.net) to fetch data in same port.Its working fine.If i connect other sql in this port its working fine.The problem is only with "Azure SQL Database server"
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.