Hi,
I have a database in SQLSERVER with some columns and it
is meant for multiple access.Now i don't want a user to interrupt the
database if some other user is modifying that database.I want to write
the code through c# ans not through SQL. please help me out.
Loading
tomcy thomasPosted Sep 25, 2009, 2:42 AM
add the namespace
using System.Data.SqlClient;
Master BillaPosted Sep 23, 2009, 12:01 PM
You need use the Transaction property
private void Trans()
{
SqlTransaction tn = null;
try
{
SqlConnection con = new SqlConnection("con string");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "query";
cmd.Connection = con;
con.Open();
//create a transaction
tn = con.BeginTransaction(IsolationLevel.Serializable);
cmd.ExecuteNonQuery();
//if success, commit the transaction
tn.Commit();
}
catch
{
if (tn != null)
{
//if error occurs, rollback the transaction
tn.Rollback();
}
}
}
Thank you
Nir BarPosted Sep 23, 2009, 8:07 AM
(Pseudo) code should be like:
Please check "Accpeted Answer" if this post helps you
Nir