本人用的是环境是Spring+Hibernate+Struts,后台是SQL Server 2000.
原来后台用的是Mysql,调试正常,后来想移植到SQL Server 2000中,仅把数据库连接相关配置文件修改了,但出错,提示:
其他异常:Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection 配置文件主要内容如下: <!-- 定义数据源Bean,使用C3P0数据源实现 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<!-- 指定连接数据库的驱动 -->
<property name="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver"/>
<!-- 指定连接数据库的URL -->
<property name="jdbcUrl" value="jdbc:microsoft:sqlserver://localhost:1433/auction"/>
<!-- 指定连接数据库的用户名 -->
<property name="user" value="sa"/>
<!-- 指定连接数据库的密码 -->
<property name="password" value="123456"/>
<!-- 指定连接数据库连接池的最大连接数 -->
<property name="maxPoolSize" value="40"/>
<!-- 指定连接数据库连接池的最小连接数 -->
<property name="minPoolSize" value="1"/>
<!-- 指定连接数据库连接池的初始化连接数 -->
<property name="initialPoolSize" value="1"/>
<!-- 指定连接数据库连接池的连接的最大空闲时间 -->
<property name="maxIdleTime" value="20"/>
</bean>    <!--定义了Hibernate的SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
<value>AuctionUser.hbm.xml</value>
<value>Bid.hbm.xml</value>
<value>Item.hbm.xml</value>
<value>Kind.hbm.xml</value>
<value>State.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
                <prop key="show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.jdbc.batch_size">20</prop> 
                <prop key="hibernate.autoReconnect">true</prop> 
            </props>
        </property>
    </bean>    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <!--  事务拦截器bean需要依赖注入一个事务管理器 -->
        <property name="transactionManager" ref="transactionManager"/>
     <property name="transactionAttributes">
    <!--  下面定义事务传播属性-->
    <props>
    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
     <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
</bean>
请多多指教!!

解决方案 »

  1.   

    log文件内容如下:
    >>>>>>>LOG4J<<<<<<< 0 2009-03-28 13:25:32,093 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 19938 2009-03-28 13:25:52,031 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 19953 2009-03-28 13:25:52,046 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - could not get database 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 com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:127)
    ... 52 more
    >>>>>>>LOG4J<<<<<<< 20047 2009-03-28 13:25:52,140 ERROR [org.hibernate.tool.hbm2ddl.SchemaUpdate] - could not complete schema update
    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 com.mchange.v2.c3p0.ComboPooledDataSource.getConnection(ComboPooledDataSource.java:521)
    (LocalSessionFactoryBean.java:807)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:740)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:131)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1062)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1029)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:420)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
    .java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
    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)
    ... 52 more
    >>>>>>>LOG4J<<<<<<< 29047 2009-03-28 13:26:01,140 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 29063 2009-03-28 13:26:01,156 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 87141 2009-03-28 13:26:59,234 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 87141 2009-03-28 13:26:59,234 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database![org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 107047 2009-03-28 13:27:19,140 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 107047 2009-03-28 13:27:19,140 ERROR [org.hibernate.util.JDBCExceptionReporter] - An SQLException was provoked by the following 
    >>>>>>>LOG4J<<<<<<< 107047 2009-03-28 13:27:19,140 ERROR failure: com.mchange.v2.resourcepool.ResourcePoolException: A ResourcePool cannot acquire a new resource -- the factory or source appears to be down.
    >>>>>>>LOG4J<<<<<<< 107047 2009-03-28 13:27:19,140 ERROR [org.hibernate.util.JDBCExceptionReporter] - An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: A ResourcePool cannot acquire a new resource -- the factory or source appears to be down.
    >>>>>>>LOG4J<<<<<<< 136172 2009-03-28 13:27:48,265 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    >>>>>>>LOG4J<<<<<<< 136172 2009-03-28 13:27:48,265 ERROR [org.hibernate.util.JDBCExceptionReporter] - Connections could not be acquired from the underlying database!
    还得多指教啊!!!