Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to sqlserver #1213

Closed
chunzhenzyd opened this issue Dec 16, 2019 · 4 comments
Closed

Cannot connect to sqlserver #1213

chunzhenzyd opened this issue Dec 16, 2019 · 4 comments
Labels
Question Used when a question is asked, as opposed to an issue being raised
Projects

Comments

@chunzhenzyd
Copy link

Driver version
8.1.1.jre8-preview

SQL Server version
2016

My code
HikariDataSource hikariDataSource = null; try { hikariDataSource = DataSourceBuilder.create().type(HikariDataSource.class).driverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver") .url("jdbc:sqlserver://192.168.30.2\\HBRGKYY:1433;databaseName=HealthOne;integratedSecurity=false;").username("sa") .password("hbegkyy@123").build(); hikariDataSource.getConnection(); log.info("test success!"); } catch (Exception exception) { log.error("test fail!", exception.getMessage()); } finally { if (hikariDataSource != null && !hikariDataSource.isClosed()) hikariDataSource.close(); }

Error
com.microsoft.sqlserver.jdbc.SQLServerException: 用户 'sa' 登录失败。 ClientConnectionId:ee138456-e5bb-4185-b30f-82de98c9d2fd
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:262)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:283)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:129)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:37)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:5169)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3810)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:94)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3754)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7218)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3053)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2562)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:2216)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:2067)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1204)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:825)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)

@chunzhenzyd chunzhenzyd added the Question Used when a question is asked, as opposed to an issue being raised label Dec 16, 2019
@chunzhenzyd
Copy link
Author

All parameters is correct, I have verified with python. But got error when using Java.

@chunzhenzyd
Copy link
Author

[root@localhost home]# java -version
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

@ulvii
Copy link
Contributor

ulvii commented Dec 16, 2019

Hi @chunzhenzyd ,
Looks like you are trying to connect to a named instance. 1433 is default instance's port, try removing it from connection string, driver should resolve the port for the named instance.
"jdbc:sqlserver://192.168.30.2\\HBRGKYY;databaseName=HealthOne;integratedSecurity=false;").username("sa") .password("hbegkyy@123").build();
See https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-ver15 for more details.

@chunzhenzyd
Copy link
Author

Hi @chunzhenzyd ,
Looks like you are trying to connect to a named instance. 1433 is default instance's port, try removing it from connection string, driver should resolve the port for the named instance.
"jdbc:sqlserver://192.168.30.2\\HBRGKYY;databaseName=HealthOne;integratedSecurity=false;").username("sa") .password("hbegkyy@123").build();
See https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-ver15 for more details.

Hi ulvii,

Thanks a lot! I will close the case.

BR

@lilgreenbird lilgreenbird added this to Closed Issues in MSSQL JDBC Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Used when a question is asked, as opposed to an issue being raised
Projects
MSSQL JDBC
  
Closed Issues
Development

No branches or pull requests

2 participants