3
Reply

Transaction

Raghvendr Singh

Raghvendr Singh

Jan 19 2011 4:31 AM
12.4k


Hi,
I am worried about these lines of code:
SqlTransaction trns = conn.BeginTransaction("tras1");
cmd = new SqlCommand("insert into E_Deatil values('Ramesh_roll',50,'address1','address2')",conn);
cmd.Transaction = trns;
cmd.ExecuteNonQuery();
In the above code one can that I did not write any code to committed transaction. Here is my two cases I run code.
Case1:
When I execute the above code from Visual Studio then a transaction runs mean while if I execute a sql query  select * from E_Deatil  in query analyzer then query is unable to retrieve data from database table because of there is already running a transaction from asp.net by the code.
As soon as I stop asp.net development server, query running in Query analyzer at once responded an I can see output in query window because I think transaction committed when I stoped asp.net development studio.  
Case2:
Now I deployed this page on local host and run same code again, the same select query in query analyzer found same result that query in query analyzer does not respond due to transaction. Here, now I closed page or stopped running web site from IIS still query in query analyzer did not responds. Why?
My anothere Question is that what is happining in first case when I stop asp.net development studio?If transaction being automatically committed? if it is then why and how because there is not any code to committe trans? 

Answers (3)