473,324 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

transaction scope

375 256MB
Hello
I am trying to run a program to check for transaction scope
I have written the following code.
But it seems I need to add a namespace or reference
What namespace am I supposed to add

thanks


using (TransactionScope scope = new TransactionScope(TransactionScope.Required, options))
{
SqlConnection MyCon = new SqlConnection("server=hemalatha\\sqlexpress;integr ated security=sspi;database=demo");
MyCon.Open();
SqlCommand Mycmd=new SqlCommand("insert into t1 values 574,'scope','10/10/2007',3,3,3");
Mycmd.ExecuteNonQuery();
SqlConnection MyCon1 = new SqlConnection("server=hemalatha\\sqlexpress;integr ated security=sspi;database=persons");
MyCon1.Open();
SqlCommand Mycmd1 = new SqlCommand("insert into persons values 'scope',123,123,12,'scope'");
Mycmd1.ExecuteNonQuery();

}
Sep 28 '07 #1
2 1725
cmrhema
375 256MB
Hello
I am trying to run a program to check for transaction scope
I have written the following code.
But it seems I need to add a namespace or reference
What namespace am I supposed to add

thanks


using (TransactionScope scope = new TransactionScope(TransactionScope.Required, options))
{
SqlConnection MyCon = new SqlConnection("server=hemalatha\\sqlexpress;integr ated security=sspi;database=demo");
MyCon.Open();
SqlCommand Mycmd=new SqlCommand("insert into t1 values 574,'scope','10/10/2007',3,3,3");
Mycmd.ExecuteNonQuery();
SqlConnection MyCon1 = new SqlConnection("server=hemalatha\\sqlexpress;integr ated security=sspi;database=persons");
MyCon1.Open();
SqlCommand Mycmd1 = new SqlCommand("insert into persons values 'scope',123,123,12,'scope'");
Mycmd1.ExecuteNonQuery();

}
Finished Transaction Scope

Use the following namespace
using System.Transactions;
By default the namespace will not be available Go to add reference and add the namespace

protected void Button2_Click(object sender, EventArgs e)
{
//Transaction Scope
//Here we use two different connections demo and demo1
//No need to use commit or rollback
//Will take implicitly only scope.complete and scope.dispose with try catch is necessary


using (TransactionScope scope = new TransactionScope())
{
int check = 0;
try
{
using (SqlConnection MyCon = new SqlConnection("server=hemalatha\\sqlexpress;integr ated security=sspi;database=demo"))
{

MyCon.Open();
SqlCommand Mycmd = new SqlCommand("insert into t1 values(2,'oooo','10/10/2007',3,3,3)", MyCon);
check=Mycmd.ExecuteNonQuery();

using (SqlConnection MyCon1 = new SqlConnection("server=hemalatha\\sqlexpress;integr ated security=sspi;database=demo1"))
{
try
{
MyCon1.Open();
check = 0;
SqlCommand Mycmd1 = new SqlCommand("insert into demotable1 values ('3','rrr')", MyCon1);
check= Mycmd1.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write("Error in 2nd");
Response.Write(ex.Message);

}
}
}
}
catch (Exception ex)
{
Response.Write("error in 1st");
Response.Write(ex.Message);
}


if (check > 0)
{
Response.Write("Transaction Committed");
scope.Complete();
}
else
{
Response.Write("Transaction RolledBack");
scope.Dispose();

}
}
}
Oct 8 '07 #2
r035198x
13,262 8TB
Please read the site's posting guidelines.
Double posting and posting code without code tags are not allowed here.
Oct 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: rdemyan via AccessMonster.com | last post by:
I have some unbound forms that I want to use transaction wrappers on when updating the table. My question is on the scope of what transaction processing will do. I'm going to keep it simple with...
4
by: liming | last post by:
Hi, I know it's possible to have transactions with Typed DataSet, but I have yet to find an example of it. For example, I have two typed TableAdapter CommerceDataSet.xsd ...
3
by: GaryDean | last post by:
I'm using TransactionScope as follows... using TransactionScope myScope = new TransactionScope()) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString =...
0
by: =?Utf-8?B?Sm9l?= | last post by:
Very weird; I lost a day worth of work because of this problem. I have an ASP.NET application written in VB that is using MySQL database. Shortly, a page creates a Customer record in the database...
1
by: =?Utf-8?B?Sm9l?= | last post by:
Very weird; I lost a day worth of work because of this problem. I have an ASP.NET application written in VB that is using MySQL database. Shortly, a page creates a Customer record in the database...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.