Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Component Services / August 2003

Tip: Looking for answers? Try searching our database.

Services Without Components?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Deyan Petrov - 21 Aug 2003 15:45 GMT
Hi guys,

I have tried the following proggie on a Windows Server 2003 of a
colleague of mine (I don't have this OS installed):

using System;
using System.EnterpriseServices;
using System.Data;
using System.Data.SqlClient;

namespace TestServiceDomain
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            DoDbOperation("db test");

            ServiceConfig config = new ServiceConfig();
            config.Transaction = TransactionOption.Required;

            try
            {
                ServiceDomain.Enter(config);

                DoDbOperation("Main");

                Method1();           

                ContextUtil.SetComplete();
            }
            catch(Exception e)
            {
                ContextUtil.SetAbort();
            }
            finally
            {
                ServiceDomain.Leave();
            }
        }

        public static void Method1()
        {
            ServiceConfig config = new ServiceConfig();
            config.Transaction = TransactionOption.Supported;

            try
            {
                ServiceDomain.Enter(config);

                DoDbOperation("Method1");

                Method2();           

                ContextUtil.SetComplete();
            }
            catch(Exception e)
            {
                ContextUtil.SetAbort();
            }
            finally
            {
                ServiceDomain.Leave();
            }
        }
        public static void Method2()
        {
            ServiceConfig config = new ServiceConfig();
            config.Transaction = TransactionOption.NotSupported;

            try
            {
                ServiceDomain.Enter(config);

                DoDbOperation("Method2");

                throw new Exception("test rollback");

                ContextUtil.SetComplete();
            }
            catch(Exception e)
            {
                ContextUtil.SetAbort();
            }
            finally
            {
                ServiceDomain.Leave();
            }
        }

        public static void DoDbOperation(string param)
        {
            SqlConnection con = new
SqlConnection("Server=SERVER_IP_HERE;Database=DB_NAME_HERE;User
ID=USERNAME_HERE;Password=PASSWORD_HERE");
            SqlCommand cmd = new SqlCommand("INSERT INTO Users(Username)
VALUES(@Username)", con);

            cmd.Parameters.Add("@Username", param);

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }

    }
}

But I got the following messagebox:
Application has generated an exception that could not be handled.
Process id .....
Click Ok to terminate ...
Click CANCEL to debug ...

I checked the db and it has a user record inserted with "db test"
username, so the db connection is ok. Obviously there is a problem
after that with the ServiceDomain. I am not sure if this is the
correct way to do transactions with SWC (as I want to mimic the
behaviour of an ordinary COM+ component with the only difference that
the transaction attributes are at the method level).

Anyone can help?

10x in advance,
Deyan Petrov
Johan Lindfors [MSFT] - 22 Aug 2003 07:58 GMT
Strange behaviour, since I just copied your code into a new Console
Application and it worked like a charm.

Have you tried debugging, and stepping through just to see which exception
gets thrown?

Regards

Signature

Johan Lindfors
Microsoft AB

This posting is provided "AS IS" with no warranties, and confers no rights.

> Hi guys,
>
[quoted text clipped - 128 lines]
> 10x in advance,
> Deyan Petrov

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.