• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Not able to connect to MS SQL 2008

 
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranch ,
I am using Hibernate and when I am trying to connect to MS SQL 2008 getting the below error.


run:
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : hello/User.hbm.xml
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: hello.User -> USER1
Dec 14, 2013 7:52:46 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Dec 14, 2013 7:52:46 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: com.microsoft.sqlserver.jdbc.SQLServerDriver at URL: jdbc:sqlserver://localhost:49158;databaseName=E2
Dec 14, 2013 7:52:46 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {user=INSPIRON-N5110/UPANSHU, password=****}
Dec 14, 2013 7:52:46 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: false
Dec 14, 2013 7:52:46 PM com.mchange.v2.log.MLog <clinit>
INFO: MLog clients using java 1.4+ standard logging.
Dec 14, 2013 7:52:46 PM com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.0.4 [built 23-January-2006 22:20:29 -0500; debug? true; trace: 10]
Dec 14, 2013 7:52:46 PM com.mchange.v2.c3p0.PoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@1a9334 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@13a317a [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 13a317a, idleConnectionTestPeriod -> 3000, initialPoolSize -> 10, maxIdleTime -> 300, maxPoolSize -> 20, maxStatements -> 50, maxStatementsPerConnection -> 0, minPoolSize -> 10, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@95c083 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 95c083, jdbcUrl -> jdbc:sqlserver://localhost:49158;databaseName=E2, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ], factoryClassLocation -> null, identityToken -> 1a9334, numHelperThreads -> 3 ]
Dec 14, 2013 7:53:16 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@1f78040 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
Dec 14, 2013 7:53:16 PM org.hibernate.cfg.SettingsFactory buildSettings
WARNING: Could not obtain connection metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:264)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2009)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1292)
at hello.HibernateUtil.buildSessionFactory(HibernateUtil.java:10)
at hello.HibernateUtil.<clinit>(HibernateUtil.java:6)
at hello.HelloWorld.main(HelloWorld.java:9)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:972)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
... 8 more
Dec 14, 2013 7:53:18 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
Dec 14, 2013 7:53:18 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Dec 14, 2013 7:53:16 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@49d67c -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
Dec 14, 2013 7:53:18 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Dec 14, 2013 7:53:18 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Dec 14, 2013 7:53:18 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Dec 14, 2013 7:53:18 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Dec 14, 2013 7:53:18 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Dec 14, 2013 7:53:18 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Dec 14, 2013 7:53:18 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Dec 14, 2013 7:53:48 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@17a4989 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
Dec 14, 2013 7:53:48 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
SEVERE: schema export unsuccessful
java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:264)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
at hello.HibernateUtil.buildSessionFactory(HibernateUtil.java:10)
at hello.HibernateUtil.<clinit>(HibernateUtil.java:6)
at hello.HelloWorld.main(HelloWorld.java:9)
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:972)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
... 10 more
Dec 14, 2013 7:54:18 PM com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
WARNING: com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@76e8a7 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30).
Dec 14, 2013 7:54:18 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 0, SQLState: null
Dec 14, 2013 7:54:18 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Connections could not be acquired from the underlying database!
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at hello.HelloWorld.main(HelloWorld.java:10)
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:104)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:264)
at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:94)
at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
... 5 more
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:972)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:208)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:260)
... 8 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 minute 32 seconds)


hibernate.cfg.xml



kindly have a look and let me know why I am getting this error.
 
Sheriff
Posts: 28368
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, like the error message says (and like your post title says), the code can't connect to the database. I would suggest writing a small test program which doesn't use Hibernate, but just uses plain old JDBC to make the connection. Then perhaps you will get a better error message.
 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul ,
good to hear from you , I ran the below test code



The error that is coming

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 0.0.0.0/UPANSHU, port 49275 has failed. Error: "null. 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 java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at various_testing.DB.main(DB.java:21)

0.0.0.0 ip I am using because I checked through netstat -aon and that is coming .
kindly suggest on this as I have spend hours on it still not solved.
Thanks


 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am using because I checked through netstat -aon and that is coming .

I don't understand the logic behind this statement, but I can almost guarantee that 0.0.0.0 is not a valid IP address for these purposes. What was wrong with "localhost" that you used earlier?

So "UPANSHU" is the instance name of your SQLServer? Note that instance names are separated by a backslash, not a forward slash: http://technet.microsoft.com/en-us/library/ms378428.aspx

And you're certain that 49275 is the correct port to use? I'm asking because earlier you used 49158, and, of course, because the standard IP used for SQLServer is 1433.
 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you Guys for showing concern in this but still error is coming ,

I am using because I checked through netstat -aon and that is coming .


I mean to say that when in cmd I run this netstat -aon command I am able to see all the ports.

I am attaching an image kindly have a look .

program code




error :

com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'INSPIRON-N5110\DELL'. ClientConnectionId:cd2de131-b3c9-4a50-be7c-8ebc096e0ff0
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
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 java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at various_testing.DB.main(DB.java:21)
BUILD SUCCESSFUL (total time: 1 second)

kindly have a look .
Thanks
Untitled.png
[Thumbnail for Untitled.png]
Screen Shot
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so now you can connect to the DB, but the credentials are wrong. The username certainly looks odd. Maybe the thing to do is to start by using a generic JDBC client (like DBVisualizer or SquirrelSQL) to make sure you have the connection parameters right.
 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf,
good to hear from you , what I was doing was that I was connecting to mssql 2008 through windows authenticate mode and not able to connect but when I changed to sql server authentication mode connection was established .
can you suggest that how to connect to sql server 2008 using windows authenticate mode.


output:

upanshu
connection established
BUILD SUCCESSFUL (total time: 0 seconds)

Thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

how to connect to sql server 2008 using windows authenticate mode.


The very first result i get when searching for that phrase looks precisely on topic, and from a site which should be the premier source of information on the subject.
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic