如何使用jdbc设置实例名称 [英] How to set instance name with jdbc

查看:163
本文介绍了如何使用jdbc设置实例名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将MS SQL服务器与jdbc驱动程序连接.我遇到了错误;

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;

我可以将此sql服务器与某些客户端应用程序(HeidiSQL)连接起来.

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:...

下面的行引发异常,我可以毫无问题地连接其他一些sql服务器.(它们没有任何实例名称)

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);

推荐答案

SQL Server实例MYINSTANCE可能未在端口1433上侦听.通常,连接URL将包含实例名称端口号,不能同时使用.同时提供两者时,必须优先.

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.

如果为HeidiSQL使用Port: 1433指定两者都允许您进行连接,则似乎HeidiSQL优先使用实例名称. SQL Server JDBC驱动程序的作用与此相反:当同时显示实例名称和端口号时,它将优先于端口号.

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

这篇关于如何使用jdbc设置实例名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆