This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate to connect to MS SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate to connect to MS SQL" Watch "Hibernate to connect to MS SQL" New topic
Author

Hibernate to connect to MS SQL

SanjayR Jain
Ranch Hand

Joined: Mar 05, 2009
Posts: 43
Hello All,

I need to connect to MS SQL 2005 using Hibernate. I am using the sqljdbc.jar and in my hibernate.cfg.xml file ,the connection url i am using is
<property name="hibernate.connection.url">jdbc:sqlserver://192.168.0.1:1433;database=test_schema</property>
.
It is throwing the following exception

org.hibernate.exception.SQLGrammarException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at TeacherAction.saveTeacher(TeacherAction.java:27)
at TeacherAction.main(TeacherAction.java:19)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'root'.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:246)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:83)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2532)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:1929)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:1917)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1061)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
... 6 more


What all changes do i need to make so that the connection gets established.



Thanks in advance
Shashank Acharya
Greenhorn

Joined: Mar 20, 2010
Posts: 21

Please use jtds jdbc driver for ms sql.
Visit below link:-
jTDS
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Shashank Acharya wrote:Please use jtds jdbc driver for ms sql.
Visit below link:-
jTDS


Well, Microsoft's own driver is OK these days so no need to change if you don't want to. And the driver is not at fault here.


Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'root'.

Looks like your credentials are wrong. You should check the ones you are using. Also its worth double checking (since this in not how SQL Server is configured out the box) you have configured your server to support connections over TCP/IP and SQL Server authentication.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
 
subject: Hibernate to connect to MS SQL
 
Similar Threads
TCP/IP connection to the host localhost, port 1433 has failed
Data source rejected establishment of connection, message from server: "Too many connections"
Error connecting to MSSQL Server from Hibernate
Deploying Hibernate 3 application in Jboss 4.0.2
Cannot open connection