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.