Click here to Skip to main content
15,914,163 members
Home / Discussions / C#
   

C#

 
AnswerRe: How do I capture an OnClosing type of event when Windows closes the app? Pin
Luc Pattyn12-Jul-07 4:25
sitebuilderLuc Pattyn12-Jul-07 4:25 
GeneralRe: How do I capture an OnClosing type of event when Windows closes the app? Pin
eb3833512-Jul-07 4:39
eb3833512-Jul-07 4:39 
GeneralRe: How do I capture an OnClosing type of event when Windows closes the app? Pin
Luc Pattyn12-Jul-07 5:02
sitebuilderLuc Pattyn12-Jul-07 5:02 
QuestionProblem in running the Instant messaging program having TCP client and server Pin
vrani12-Jul-07 2:24
vrani12-Jul-07 2:24 
AnswerRe: Problem in running the Instant messaging program having TCP client and server Pin
Christian Graus12-Jul-07 2:29
protectorChristian Graus12-Jul-07 2:29 
GeneralRe: Problem in running the Instant messaging program having TCP client and server Pin
vrani12-Jul-07 2:42
vrani12-Jul-07 2:42 
GeneralRe: Problem in running the Instant messaging program having TCP client and server Pin
Christian Graus12-Jul-07 3:05
protectorChristian Graus12-Jul-07 3:05 
QuestionThe magic of TransactionScope Pin
Le centriste12-Jul-07 1:45
Le centriste12-Jul-07 1:45 
Here is an example of a use of the TransactionScope class:

using (TransactionScope ts = new TransactionScope())
{
    //Create and open the SQL connection.  The work done on this connection will be a part of the transaction created by the TransactionScope
    SqlConnection myConnection = new SqlConnection("server=(local)\\SQLExpress;Integrated Security=SSPI;database=northwind");
    SqlCommand myCommand = new SqlCommand();
    myConnection.Open();
    myCommand.Connection = myConnection;

    //Restore database to near it's original condition so sample will work correctly.
    myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)";
    myCommand.ExecuteNonQuery();

    //Insert the first record.
    myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')";
    myCommand.ExecuteNonQuery();

    //Insert the second record.
    myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')";
    myCommand.ExecuteNonQuery();

    myConnection.Close();

                    //Call complete on the TransactionScope or not based on input
    ConsoleKeyInfo c;
    while (true)
    {
                            Console.Write("Complete the transaction scope? [Y|N] ");
        c = Console.ReadKey();
        Console.WriteLine();

        if ((c.KeyChar == 'Y') || (c.KeyChar == 'y'))
        {
            // Commit the transaction
            ts.Complete();
            break;
        }
        else if ((c.KeyChar == 'N') || (c.KeyChar == 'n'))
        {
            break;
        }
    }
}


The above piece of code is taken directly from MSDN. At one point, if the user answers 'Y', the ts.Complete() method is called, which makes the Dispose() method commit the transaction (or rollback it if the user answers 'N').

How is the SqlConnection instance associated with the TransactionScope? Is this magic happening under the hood?

-----

If atheism is a religion, then not collecting stamps is a hobby. -- Unknown

JokeRe: The magic of TransactionScope Pin
Luc Pattyn12-Jul-07 1:53
sitebuilderLuc Pattyn12-Jul-07 1:53 
JokeRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 1:54
Le centriste12-Jul-07 1:54 
GeneralRe: The magic of TransactionScope Pin
Martin#12-Jul-07 1:59
Martin#12-Jul-07 1:59 
AnswerRe: The magic of TransactionScope Pin
Christian Graus12-Jul-07 2:41
protectorChristian Graus12-Jul-07 2:41 
GeneralRe: The magic of TransactionScope Pin
Martin#12-Jul-07 2:47
Martin#12-Jul-07 2:47 
GeneralRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 2:51
Le centriste12-Jul-07 2:51 
AnswerRe: The magic of TransactionScope Pin
Pete O'Hanlon12-Jul-07 2:49
mvePete O'Hanlon12-Jul-07 2:49 
GeneralRe: The magic of TransactionScope Pin
Le centriste12-Jul-07 2:53
Le centriste12-Jul-07 2:53 
AnswerRe: The magic of TransactionScope Pin
Judah Gabriel Himango12-Jul-07 5:05
sponsorJudah Gabriel Himango12-Jul-07 5:05 
Questionhow to close child form on the click event of toolstrip button Pin
monuSaini12-Jul-07 0:44
monuSaini12-Jul-07 0:44 
AnswerRe: how to close child form on the click event of toolstrip button Pin
Bekjong12-Jul-07 2:04
Bekjong12-Jul-07 2:04 
QuestionC# USB Detection [modified] Pin
donovan.solms12-Jul-07 0:43
donovan.solms12-Jul-07 0:43 
AnswerRe: C# USB Detection Pin
Giorgi Dalakishvili12-Jul-07 1:10
mentorGiorgi Dalakishvili12-Jul-07 1:10 
AnswerRe: C# USB Detection Pin
Martin#12-Jul-07 1:38
Martin#12-Jul-07 1:38 
GeneralRe: C# USB Detection Pin
donovan.solms12-Jul-07 1:54
donovan.solms12-Jul-07 1:54 
QuestionHow to convert CSV file to XLS file using C# Programme Pin
liyakhat_shahid12-Jul-07 0:27
liyakhat_shahid12-Jul-07 0:27 
AnswerRe: How to convert CSV file to XLS file using C# Programme Pin
Bijesh12-Jul-07 1:06
Bijesh12-Jul-07 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.