Test the transaction. If the table has an auto-increment field not submitted, whether the ID has been generated.

Source: Internet
Author: User

 

 

Class program {

Static void main (string [] ARGs)

{

Console. writeline ("enter the program id :");

Consolekeyinfo cki = console. readkey ();

Using (sqlconnection con = new sqlconnection (conn ))

{

Con. open ();

Sqltransaction TRAN = con. begintransaction ();

Object OBJ = sqlhelper. executescalar (Tran, system. Data. commandtype. Text, "insert into test (spi_id) values (" + cki. keychar + ")");

OBJ = sqlhelper. executescalar (Tran, system. Data. commandtype. Text, "select ident_current ('test ')");

Console. writeline (environment. newline + "submit by Y, other rollback, current ID is" + obj. tostring ());

Cki = console. readkey ();

If (cki. keychar. Equals ('y '))

Tran. Commit ();

Else

Tran. rollback ();

}

}

Static string conn = @ "Data Source = 127.0.0.1; initial catalog = test; persist Security info = true; user id = sa; Password = 1 ";

}

 

1. The transaction has not been commit and the ID can be read.

2. If both apps open transactions and are not committed, each has a new ID.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.