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:
- adding all relevant hibernate jars and
sqljdbc41.jar
(sql server jdbc driver) to my project. - added an xml with the following
sqljdbc_auth.dll
(x64) to the environment path. 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