Trying to connect to SQL Server 2008 Express database with SQL Server authentication always result in "Login failed for user '...'."

StackOverflow https://stackoverflow.com/questions/16351326

Question

I am using jTDS to connect a Liferay instance to an SQL Server 2008 Express server using the SQL Server authentication (instead of the Windows' auth method). I have something like this in my portal-ext.properties:

jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
jdbc.default.url=jdbc:jtds:sqlserver://127.0.0.1:1433/somedb
jdbc.default.username=someuser
jdbc.default.password=somepassword

(For those that do not know Liferay, it is somewhat alike to call

Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = DriverManager.getConnection("jdbc:jtds:sqlserver://127.0.0.1:1433/somedb",
                                  "someuser", "somepassword");

However, although I pass the correct username and password, it keeps going wrong with the message Login failed for user 'someuser'. I am dead sure the server login, the database user and the database exists and are well configured.

What can be wrong?

Was it helpful?

Solution

Well, I suppose there can be infinite reasons for such an error. In my case, nonetheless, the solution was the following:

  1. Enable the TCP/IP connection in SQL Configuration Manager.

  2. Open the SQL Server Management Studio (if you do not have it installed, install it; it can have its own pitfalls, however).

  3. Right-click on the database server (as in the picture below) and click in Properties. Right-clicking on the database server

  4. Select the Security option and mark SQL Server and Windows authentication mode. Click in OK. Database server Security properties
  5. Open the SQL Server Configuration Manager and restart the SQL Server service.

After this, I got my connections without problems. This article helped me a lot.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top