This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate to connect to MS SQL" Watch "Hibernate to connect to MS SQL" New topic

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://;database=test_schema</property>
It is throwing the following exception

org.hibernate.exception.SQLGrammarException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.jdbc.ConnectionManager.openConnection(
at org.hibernate.jdbc.ConnectionManager.getConnection(
at org.hibernate.jdbc.JDBCContext.connection(
at org.hibernate.transaction.JDBCTransaction.begin(
at org.hibernate.impl.SessionImpl.beginTransaction(
at TeacherAction.saveTeacher(
at TeacherAction.main(
Caused by: Login failed for user 'root'.
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(
at org.hibernate.jdbc.ConnectionManager.openConnection(
... 6 more

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

Thanks in advance
Shashank Acharya

Joined: Mar 20, 2010
Posts: 21

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

Joined: Apr 14, 2004
Posts: 10336

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

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: 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
I agree. Here's the link:
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