PRB: Cannot Start a Clones Connection While In Manual Transaction Mode

xiaoxiao2021-03-06  62

JDBC Connect SQL2000 Times Wrong:

PRB: Cannot Start a Clones Connection While In Manual Transaction Mode

Suitable

This Article Was previously distribLished Under Q313181

Symptomswhile 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 Clones CONNECTION WHILE IN MANUAL Transaction Mode.

CAUSEThis 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 .

Resolutionwhen 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 article.

Statusthis Behavior Is By Design.

More information

Steps to reproduce the Behavioruse the Following Code to Reproduce The Error:

Note: See The Comments in The Channel for Information On The Change 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.sqlser.sqlserverdriver);

Con = DriverManager.getConnection

"JDBC: Microsoft: SQLSERVER: // localhost: 1433; DatabaseName = Pubs; selectMethod = Direct; user = user; password = password");

// FIX 1

//"jdbc:///localhost:1433; DatabaseEname =pubs;selectmethod=cursor; ●  ^ p = = =cw er" ;";

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 ();

}

}

}

REFERENCESFor 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

转载请注明原文地址:https://www.9cbs.com/read-111977.html

New Post(0)