Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in accessing database in SQL Server using Java

 
sachin bal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an SQL Server 2012 edition. I have two databases on this server. One of these databases named BANKTEST was restored from a backup a few months ago. I have recently restored another database named NEWBANK.

The following is the java program which I had written to access NEWBANK


Unfortunately, I am getting an error which I have listed below

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "NEWBANK" requested by the login. The login failed. ClientConnectionId:69c57dd7-38b1-413c-b8ea-8d53824f74e1 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216) at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254) at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84) at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908) at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234) at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41) at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.example.myproject.client.ConnectMSSQL.main(ConnectMSSQL.java:13)


If I replace the name of the database with BANKTEST, I do not get any errors. Can someone advice me on this?

Regards

Sachin
 
Ron McLeod
Bartender
Pie
Posts: 1044
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your connection line specifies a database name of NEWBANk (lower-case 'k') -- are database names in SQLServer case-sensistive?

If that is not the problem, verify that user sa has been granted permission to access the database.
 
sachin bal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the response, Ron.

I changed the name to NEWBANK and tested again. Unfortunately, it does not work. Also, the user sa has been granted permission to access the database NEWBANK

Regards

Sachin Bal
 
Ron McLeod
Bartender
Pie
Posts: 1044
65
Android Eclipse IDE Java Linux MySQL Database Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using sqlcmd or some other utility to see if you experience the same problem. Even if it does also fail, the other tools may provide you some additional information.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the SQL Server logs to see if it records an attempted login. It could simply be the user not having the rights to login. (It can be a bit confusing, as adding a user in SQL Server does not necessarily mean it can login.) Make sure you can login with that username from the console.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic