PRB: Cannot Start a Cloned Connection While in Manual Transaction Mode

原创 2004年09月29日 09:45:00
JDBC连接SQL2000时报错:

PRB: Cannot Start a Cloned Connection While in Manual Transaction Mode

适用于
This article was previously published under Q313181

SYMPTOMS

While using the Microsoft SQL Server 2000 Driver for JDBC, you may experience the following exception:

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection while in manual transaction mode.

CAUSE

This error occurs when you try to execute multiple statements against a SQL Server database with the JDBC driver while in manual transaction mode (AutoCommit=false) and while using the direct (SelectMethod=direct) mode. Direct mode is the default mode for the driver.

RESOLUTION

When you use manual transaction mode, you must set the SelectMethod property of the driver to Cursor, or make sure that you use only one active statement on each connection as specified in the "More Information" section of this article.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

Use the following code to reproduce the error:

NOTE: See the comments in the code for information on the code changes that are required to resolve the problem.
import java.sql.*;
import java.io.*;


public class Repro{

	public static void main(String args[])
	{
		try {
			Connection con;
			Statement s1 = null;
			ResultSet r1 = null;
			Statement s2 = null;
			ResultSet r2 = null;
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
			con = DriverManager.getConnection(
				"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Direct;User=User;Password=Password");
			//fix 1
				//"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs;SelectMethod=Cursor;User=User;Password=Password");
			con.setAutoCommit(false);
			
			try {
				s1 = con.createStatement();
				r1 = s1.executeQuery("SELECT * FROM authors");
				
				//fix 2
				//r1.close();
				//s1.close();

				s2 = con.createStatement();
				r2 = s2.executeQuery("SELECT * FROM publishers");
			}
			catch (SQLException ex)
			{
				System.out.println(ex);				
			}
		
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
				

REFERENCES

For more information about Cloned Connections, see the Connection String Properties section of the Microsoft SQL Server 2000 Driver for JDBC HTML Help or the Online Guide.For additional information about cloned connections with the driver, click the article number below to view the article in the Microsoft Knowledge Base:

313220 PRB: Unexpected Connections to SQL Server with JDBC

The information in this article applies to:

  • Microsoft SQL Server 2000 Driver for JDBC

Can't start a cloned connection while in manual transaction mode.错误的解决方案

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Cant start a cloned connection whi...
  • zjx2388
  • zjx2388
  • 2009年02月24日 14:25
  • 3317

SQL Server 解决Can't start manual transaction mode问题

SQL Server 解决Can't start manual transaction mode问题
  • a9529lty
  • a9529lty
  • 2011年01月05日 20:43
  • 1295

JDBC连SQL SERVER数据库常见问题Can't start a cloned connection while(转载)

--问题1:出现ClassNotFoundException,这个问题是由于你没有把driver类放到你的classpath中,也就是说你的程序找不到驱动类,包括三个包:msutil.jar,msba...
  • eagelangel
  • eagelangel
  • 2009年09月20日 10:28
  • 1555

Can't start a cloned connection while in manual transaction mode

 解决方案:(1)你在尝试打开一个克隆连接,有两种解决办法: 每个数据库的连接在执行完毕后,关闭,第二,在连接时,判断是否已经有连接存在,有则使用现成的连接。 数据库连接可以设置成一个常量,不需要到处...
  • ivan_zhang_blog
  • ivan_zhang_blog
  • 2007年04月20日 10:23
  • 1983

Can't start a cloned connection while in manual transaction mode.

Cant start a cloned connection while in manual transaction mode. sql server数据库在代码中数据是手动提交的,包了上面的错误,将...
  • zjx2388
  • zjx2388
  • 2008年08月22日 09:14
  • 620

sQLite问题:Error cannot start a transaction within a transaction

SQLite3事务模式问题? 我用SQLite3在同一个数据库里面同时操作三个表单table,使用事务模式插入数据,提示2个错误“Error cannot start a transacti...
  • petershina
  • petershina
  • 2014年08月27日 09:16
  • 4079

Can't start a cloned connection while in manual transaction mode 解决

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can't start a cloned connection wh...
  • ch717828
  • ch717828
  • 2015年01月25日 14:31
  • 597

Can't start a cloned connection while in manual transaction mode的解决方法

出现该异常的原因是原来的Hibernate的连接池的连接速度以及管理模式都不够好,所以本人换了第三方的c3p0连接池.之后就出现了这个异常.在网上查了一下原因在手工事务模式 (AutoCommit=f...
  • qinghua9
  • qinghua9
  • 2007年09月21日 15:33
  • 1224

Sql Server2000 Can't start a cloned connection while in manual transaction mode

Sql Server2000设置事务时 conn.setAutoCommit(false); //执行语句sql1,sql2 conn.commit(); 结果出现Can't start a ...
  • bell2008
  • bell2008
  • 2013年04月03日 23:48
  • 596

[Microsoft][SQLServer JDBC Driver]Can't start a cloned connection while in manual transaction mode

SYMPTOMSloadTOCNode(1, symptoms);While using the Microsoft SQL Server 2000 Driver for JDBC, you may ...
  • nickshen3
  • nickshen3
  • 2006年08月11日 10:22
  • 1191
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:PRB: Cannot Start a Cloned Connection While in Manual Transaction Mode
举报原因:
原因补充:

(最多只允许输入30个字)