title: "Error calling Driver#connect" using Hibernate
body: <p>This is my cfg.xml file:
  </p>
  
  <pre><code>    &lt;!-- Database connection settings --&gt;
      &lt;property name="connection.driver_class"&gt;com.microsoft.sqlserver.jdbc.SQLServerDriver&lt;/property&gt;
      &lt;property name="connection.url"&gt;jdbc:sqlserver://localhost:1433;DatabaseName=hiber;&lt;/property&gt;
      &lt;property name="connection.username"&gt;Costi-PC\Costi&lt;/property&gt;
      &lt;property name="connection.password"&gt;&lt;/property&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
      &lt;!-- SQL dialect --&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.SQLServerDialect&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache --&gt;
      &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop and re-create the database schema on startup --&gt;
      &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt;
  
      &lt;!-- Names the annotated entity class --&gt;
      &lt;mapping class="model.User" /&gt;
  </code></pre>
  
  <p>User class and Main class:</p>
  
  <pre><code>@Entity
      public class User {
  
          @Id
          private int userId;
          private String userName;
  
          public int getUserId() {..}
          public void setUserId(int userId) {..}
          public String getUserName() {..}
          public void setUserName(String userName) {..}
  
      }
  
      public class Main {
  
          public static void main(String[] args) {
             User user = new User();
             user.setUserId(1);
             user.setUserName("Costi");
  
             AnnotationConfiguration configuration = new AnnotationConfiguration();
             configuration.configure();
  
             SessionFactory sessionFactory = configuration.buildSessionFactory();
  
             Session session = sessionFactory.openSession();
             session.beginTransaction();
             session.save(user);
             session.getTransaction().commit();
             session.close();
  
             sessionFactory.close();
  
  }
  </code></pre>
  
  <p>When I run the program i get this error: </p>
  
  <pre><code>Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:118)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
      at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
      at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
      at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
      at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
      at main.Main.main(Main.java:23)
  Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
      at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
      at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:241)
      at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2243)
      at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:491)
      at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1309)
      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 org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
      ... 14 more
  </code></pre>
  
  <p>I'm using sql server 2008.
  I tried different types of cfg configuration  but none seems to work.
  I believe the problem is from connection.url. I tried to change the port (1433) but nothing.
  Can anyone tell what's the problem ?</p>