Re: Behavior of Connection.commit()
- From: "Angel Saenz-Badillos[MS]" <angelsa@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 20 Jan 2006 16:04:27 -0800
Thank you for taking the time to test this with another driver. The
intention of the program is to show that with this driver when you get this
type of data corruption we will throw on Commit. It is an ugly problem, but
to us it seemed like a better option than having commit succeed and silently
corrupting your data.
This is why I mentioned that this could be a very serious error, your code
could be silently corrupting your data with your previous driver. With this
driver you can at least realize that there may be a problem but it will
probably require code changes to fix the underlying issue.
>I don't understand
> how your program expects the commit to fail, but
> then expects the row inserted in a failed tx to still
> be there?
I am sorry for not making it clearer, I am afraid I just threw it together
to post it while everybody is looking at this thread. The program was
intended to show that others drivers that don't throw on commit still have
the same data corruption issue.
--
Angel Saenz-Badillos [MS] DataWorks
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
I am now blogging: http://weblogs.asp.net/angelsb/
"Joe Weinstein" <joeNOSPAM@xxxxxxx> wrote in message
news:43D17774.7090200@xxxxxxxxxx
> Ok, I just tested another driver that fails the tx because
> the table is there. The subsequent commit does not fail.
> The select gives only the 9999 row. I don't understand
> how your program expects the commit to fail, but
> then expects the row inserted in a failed tx to still
> be there?
> Joe
>
> Angel Saenz-Badillos[MS] wrote:
>
>> Just a quick repro program that explains the problem, I would be
>> interested to see how other Sql Server drivers handle this:
>>
>> import java.lang.*;
>> import java.util.*;
>> import java.sql.*;
>> import java.math.*;
>> import java.text.*;
>> import java.io.*;
>>
>> public class test
>> {
>> public static String ConnectionString = "<set your connection string
>> here>";
>>
>> public static void main(String[] args) throws Exception
>> {
>> Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
>> Connection conn = DriverManager.getConnection(ConnectionString);
>> Statement stmt = conn.createStatement();
>> String tablename= "testTX";
>> stmt.executeUpdate("if exists (select * from dbo.sysobjects where id =
>> object_id(N'[dbo].[" + tablename + "]') and OBJECTPROPERTY(id,
>> N'IsUserTable') = 1) DROP TABLE [" + tablename + "]");
>> stmt.executeUpdate("CREATE TABLE [" + tablename + "] (a int)");
>>
>> conn.setAutoCommit(false);
>> stmt.executeUpdate("INSERT into [" + tablename+ "] values (1)");
>> try{
>> //This will kill the transaction!
>> stmt.executeUpdate("CREATE TABLE [" + tablename + "] (a int)");
>> }catch(Exception ex){System.out.println(ex.getMessage());}
>> stmt.executeUpdate("INSERT into [" + tablename+ "] values (99999)");
>> try{
>> conn.commit();
>> }catch(Exception ex){System.out.println("We correctly throw an
>> exception: "+ex.getMessage());}
>> conn.close();
>>
>> //Verify data inserted.
>> Connection conn2 = DriverManager.getConnection(ConnectionString);
>> Statement stmt2 = conn2.createStatement();
>> ResultSet rs = stmt2.executeQuery("SELECT * FROM [" + tablename + "]");
>> while(rs.next()){
>> System.out.println(rs.getObject(1));
>> }
>> System.out.println("If this did not print out 2 lines: 1, 99999 you
>> have data corruption.");
>> }
>> }
>>
>>
>>
>>
>
.
- Follow-Ups:
- Re: Behavior of Connection.commit()
- From: Joe Weinstein
- Re: Behavior of Connection.commit()
- References:
- Re: Behavior of Connection.commit()
- From: Joe Weinstein
- Re: Behavior of Connection.commit()
- From: Joe Weinstein
- Re: Behavior of Connection.commit()
- From: Angel Saenz-Badillos[MS]
- Re: Behavior of Connection.commit()
- From: Joe Weinstein
- Re: Behavior of Connection.commit()
- From: Angel Saenz-Badillos[MS]
- Re: Behavior of Connection.commit()
- From: Joe Weinstein
- Re: Behavior of Connection.commit()
- From: Angel Saenz-Badillos[MS]
- Re: Behavior of Connection.commit()
- From: Joe Weinstein
- Re: Behavior of Connection.commit()
- Prev by Date: Re: Behavior of Connection.commit()
- Next by Date: Re: Behavior of Connection.commit()
- Previous by thread: Re: Behavior of Connection.commit()
- Next by thread: Re: Behavior of Connection.commit()
- Index(es):
Relevant Pages
|
Loading