Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2013
    Posts
    21

    Unanswered: jdbc connection problems

    Hi All,

    I try to run a JAVA program with a connection to SQL Server 2012.
    This program works very well with MySQL, Oracle and DB2.
    But I have problem with SQL Server:

    Code:
    Caused by: org.hibernate.HibernateException: 'hibernate.dialect' must be set when no Connection available
    	at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:106)
    	at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:148)
    	at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833)
    	at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840)
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902)
    	... 51 more
    My connection parameters are stored in propertie file :
    Code:
    Url=jdbc:sqlserver://NASSA\\SQLEXPRESS:1433;database=MyDB
    Username=nassa
    Password=nassa
    DriverClassName=com.microsoft.sqlserver.jdbc.SQLServerDataSource
    These parameters are copied to a datasource.

    I use sqljdbc4.jar driver file.

    I have no problem to connect to my database with oqsl.exe or sqlcmd.exe:
    Code:
    >sqlcmd -S NASSA\SQLEXPRESS -U nassa -P nassa -d MyDB
    Thanks for your help.

    Nassa.

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    The default port for a named instance is usually randomized. Take off the ":1433" or use SQL Server's configuration manager to set the port on the named instance.

  3. #3
    Join Date
    Feb 2013
    Posts
    21
    Thanks MCrowley,

    But without port number, it does not work.

    I set port number 1433 in the "SQL Server Configuration Manager"
    Code:
    o-> SQL Server Configuration Manager (Local)
          |-> SQL Server Network Configuration
                |-> Protocols for SQLEXPRESS
                      |->TCP/IP
    I opened the properties window.
    In the IP Address tab.
    I set All TCP Dynamic Ports : "blank"
    I set All TCP Port to : 1433

    I restarted the SQL Server :
    Code:
    o-> SQL Server Configuration Manager (Local)
          |-> SQL Server (SQLEXPRESS)
    When I use this command line :
    Code:
    >sqlcmd -S NASSA\SQLEXPRESS,1433 -U nassa -P nassa -d MyDB
    Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : TCP Provider: Aucune connexion n'a pu être établie car l'ordinateur cible l'a expressément refusée.
    .
    Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login timeout expired.
    Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
    But, if I use this command line :
    Code:
    >sqlcmd -S NASSA\SQLEXPRESS -U nassa -P nassa -d MyDB
    It's Ok.

    I undrestand nothing !

    Nassa.

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    For optimal connection performance, you should set the portNumber when you connect to a named instance. This will avoid a round trip to the server to determine the port number. If both a portNumber and instanceName are used, the portNumber will take precedence and the instanceName will be ignored.

    Building the Connection URL

  5. #5
    Join Date
    Feb 2013
    Posts
    21
    Ok pdreyer,

    The problem is that I can not set the port number!
    It does not work!

    Thanks.

    Nassa.
    Last edited by nassarane; 04-05-13 at 09:08.

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    in this example:
    Code:
    >sqlcmd -S NASSA\SQLEXPRESS,1433 -U nassa -P nassa -d MyDB
    You are asking SQLCMD to look for an instance called "SQLEXPRESS,1433" on the server named NASSA. This instance does not exist, so you get an error.

    Try this:
    Code:
    >sqlcmd -S NASSA,1433 -U nassa -P nassa -d MyDB
    Anything after the "\" (except whitespace) is considered to be the instance name.

  7. #7
    Join Date
    Feb 2013
    Posts
    21
    Thanks very much,

    IT WORKS !!!

    For jdbc connection I use this :
    Code:
    Url=jdbc:sqlserver://localhost:1433;database=MyDB
    Thanks very much for your help MCrowley !

    Nassa.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •