0
votes

I am tring create connection for sql server database using azure hybrid connection and my database server is sql server instance and it's name is something like this serverName/instance and my java code to connect the database server is similar to this

DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setUrl("jdbc:sqlserver://serverName/instance;database=database;user=userName;password=password;useSSL=false");

and aliasing works perfectly in local but when i deploy the code to azure it's telling can't able to connect to server "serverName".

1
To connect using an instance name you must connect to the SQL Browser on UDP port 1434 to look up the SQL Server instance'sTCP/IP port. I doubt that will work through hybrid connections. Try connecting with a port number instead of an instance name. If you SQL Server uses a dynamic port, you may have to change to a fixed port. - David Browne - Microsoft
@shridhar did you find a solution, I am also facing the same issue, locally it works, but not after deployment - Jeba Prince

1 Answers

1
votes

SQL Server connection string template:

String connectionUrl = "jdbc:sqlserver://<server>:<port>;databaseName=AdventureWorks;user=<user>;password=<password>";

You can change you code like this and replace your port number. For example:

DriverManagerDataSource dataSource = new DriverManagerDataSource();

dataSource.setUrl("jdbc:sqlserver://serverName/instance:1433;database=database;user=userName;password=password;useSSL=false");

Reference: Connection URL Sample.

Hope this helps.