How to set instance name with jdbc

空扰寡人 提交于 2021-02-05 11:34:50

问题


I am trying to connect a MS SQL server with jdbc driver. I am getting below error;

Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall

I think there is a problem with my connection URL. Here is my connection URL;

jdbc:sqlserver://50.50.50.50\MYINSTANCE:1433;

EDIT: I can connect this sql server with some client application(HeidiSQL) without any problem.

Network type: Microsoft SQL server (tcp/ip)
Hostname:50.50.50.50\MYINSTANCE
Port: 1433
username:...
password:...

Below line throws exception and I can connect some other sql server's without any problem.(They don't have any instance name)

DriverManager.getConnection(connectionUrl, username, password);

回答1:


The SQL Server instance MYINSTANCE is probably not listening on port 1433. Normally, a connection URL will include an instance name or a port number, not both. When both are supplied, one must take precedence.

If specifying both with Port: 1433 for HeidiSQL allows you to connect then it seems that HeidiSQL is giving precedence to the instance name. The SQL Server JDBC driver does the opposite: when presented with both an instance name and a port number it will give precedence to the port number.

So, you should be able to connect using a URL like this:

jdbc:sqlserver://50.50.50.50;instanceName=MYINSTANCE



回答2:


Check if there is no rule blocking TCP connection on cmd do the

telnet 127.0.0.1 1433

and also check in your SQL server configuration the TCP port is correct or not.



来源:https://stackoverflow.com/questions/40356685/how-to-set-instance-name-with-jdbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!