1

I am trying to connect to a database using hibernate, I have read the documentation and user guild but I still cannot connect to the database. The steps which I took:

  1. adding all relevant hibernate jars and sqljdbc41.jar (sql server jdbc driver) to my project.
  2. added an xml with the following sqljdbc_auth.dll (x64) to the environment path.
  3. created a xml by the name hibernate.cfg.xml with the following connection and dialect:

        <!-- Database connection settings -->
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.url">"jdbc:sqlserver://localhost;databaseName=ForumSystem;integratedSecurity=true;"</property>
    
    <!-- SQL dialect -->
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    

as you can see my server is local and I am using windows authentication, also I did not change the defualt instance and port.

I try to connection to the databse using the following code:

 Configuration configuration = new Configuration();
    configuration.configure();
    serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
            configuration.getProperties()).build();
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);

and I get the following error:

Exception in thread "main" org.hibernate.HibernateException: Unable to make JDBC Connection ["jdbc:sqlserver://SHPERB;databaseName=ForumSystem;integratedSecurity=true;"]

I have tried to modify the connection url to include the port and the instance name anyway and also tried to connect without windows authentication but made no progress.

Have I missed something? is there a way to know which of the parameters is wrong?

Edit: forgot to mention that TCP\IP is enabled in the SQL server configuration and that I allow both windows authentication and SQL authentication in the database. If I try to connect using:

String connectionUrl = "jdbc:sqlserver://SHPERB;database=ForumSystem;integratedSecurity=true;";
Connection con = DriverManager.getConnection(connectionUrl);

it works, but not using hibernate

Shperb
  • 474
  • 7
  • 19

1 Answers1

0

Try to add jdbc:microsoft:sqlserver in your url. Yoou need to specify driver for Microsoft SQL JDBC Driver. See more Connecting to MS sql through hibernate and how to configure hibernate config file for sql server

Also check whether custom port is set and add it into the connection params.

Community
  • 1
  • 1
StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • Accordong to the documentation, there sould not be "microsoft:", I tested is just to make sure but it did not help. And about the port, I took the connection string from the database which I already integreated to eclipse, and it uses the default port. – Shperb Apr 23 '15 at 09:31