0

I'm trying to connect to microsoft sql server using 8.2 version of jar.

It works fine when I'm using the same username, password in DBeaver. I'm not using any additional options in the connection string of DBeaver. I'm using the type SQLServer Authentication. It gets connected in DBeaver but I'm not able to open a connection via Scala repl.

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
val props=new java.util.Properties

props.put("user","")
props.put("password","")

// URL : jdbc:sqlserver://host:port // No additional options like in DBeaver

DriverManager.getConnection("url",props)

Error:

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'USERNAME'. ClientConnectionId:CONNECTIONID
  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:5173)
  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:7225)
  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 java.sql.DriverManager.getConnection(DriverManager.java:664)
  at java.sql.DriverManager.getConnection(DriverManager.java:208)
  ... 47 elided

tempUser
  • 49
  • 6
  • Client-side error messages for login failures are intentionally obtuse - you don't want to make it easy for hackers! If you have access to the SQL Server instance, such as through SSMS (or maybe DBeaver can do it), check the ERRORLOG for `Error 18456` messages, take note of the `State` number there and compare it against the `State` numbers listed at [MSSQLSERVER_18456](https://learn.microsoft.com/en-us/sql/relational-databases/errors-events/mssqlserver-18456-database-engine-error) to determine the actual problem. As a first step, bear in mind that passwords are case-sensitive! – AlwaysLearning Sep 09 '22 at 07:08
  • Where Can I find This error LOG – tempUser Sep 09 '22 at 08:01
  • Does this answer your question? [Receiving SQLException "Login failed for user" connecting to SQL Server 2008](https://stackoverflow.com/questions/14945075/receiving-sqlexception-login-failed-for-user-connecting-to-sql-server-2008) – Anna Gevel Sep 12 '22 at 21:30

0 Answers0