List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:August 4 2009 3:04pm
Subject:bzr commit into connector-net-5.2 branch (reggie.burnett:703) Bug#46375
View as plain text  
#At file:///D:/bzr-connector-net/5.2/ based on revid:reggie.burnett@stripped

  703 Reggie Burnett	2009-08-04
      removed usage of TransactionScope from web providers so that they work properly on Mono 2.0 (bug #46375)

    modified:
      CHANGES
      MySql.Web/Providers/MySql.Web.csproj
      MySql.Web/Providers/Source/MembershipProvider.cs
      MySql.Web/Providers/Source/ProfileProvider.cs
      MySql.Web/Providers/Source/RoleProvider.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2009-07-31 22:51:28 +0000
+++ b/CHANGES	2009-08-04 15:04:03 +0000
@@ -7,6 +7,8 @@
   out of order while using the 'use procedure bodies=false' option would fail (bug #46213)
 - fixed mono compilation by removing the space delimited warning list from the project file
   and including a solution that builds with MonoDevelop 2.0. (bug #42411)
+- removed usage of TransactionScope from web providers so that they work properly
+  on Mono 2.0 (bug #46375)
 
 Version 5.2.7 7/13/09
 - fixed procedure parameters collection so that an exception is thrown if we can't get the 

=== modified file 'MySql.Web/Providers/MySql.Web.csproj'
--- a/MySql.Web/Providers/MySql.Web.csproj	2009-07-28 20:13:31 +0000
+++ b/MySql.Web/Providers/MySql.Web.csproj	2009-08-04 15:04:03 +0000
@@ -46,7 +46,6 @@
     <Reference Include="System.Configuration.Install" />
     <Reference Include="System.Data" />
     <Reference Include="System.Management" />
-    <Reference Include="System.Transactions" />
     <Reference Include="System.Web" />
     <Reference Include="System.Xml" />
   </ItemGroup>

=== modified file 'MySql.Web/Providers/Source/MembershipProvider.cs'
--- a/MySql.Web/Providers/Source/MembershipProvider.cs	2009-07-28 20:13:31 +0000
+++ b/MySql.Web/Providers/Source/MembershipProvider.cs	2009-08-04 15:04:03 +0000
@@ -37,7 +37,6 @@
 using MySql.Web.Properties;
 using MySql.Web.Profile;
 using MySql.Web.Common;
-using System.Transactions;
 using System.Text.RegularExpressions;
 using MySql.Web.General;
 

=== modified file 'MySql.Web/Providers/Source/ProfileProvider.cs'
--- a/MySql.Web/Providers/Source/ProfileProvider.cs	2009-03-04 16:20:51 +0000
+++ b/MySql.Web/Providers/Source/ProfileProvider.cs	2009-08-04 15:04:03 +0000
@@ -35,7 +35,6 @@
 using System.Data;
 using System.IO;
 using System.Globalization;
-using System.Transactions;
 using System.Web.Security;
 using MySql.Web.Common;
 using MySql.Web.Properties;
@@ -459,50 +458,53 @@
             int count = EncodeProfileData(collection, isAuthenticated, ref index, ref stringData, ref binaryData);
             if (count < 1) return;
 
+            MySqlTransaction txn = null;
+
             // save the encoded profile data to the database
-            try
+            using (MySqlConnection connection = new MySqlConnection(connectionString))
             {
-                using (TransactionScope ts = new TransactionScope())
+                try
                 {
-                    using (MySqlConnection connection = new MySqlConnection(connectionString))
+                    connection.Open();
+
+                    txn = connection.BeginTransaction();
+
+                    // either create a new user or fetch the existing user id
+                    int userId = SchemaManager.CreateOrFetchUserId(connection, username, 
+                        app.EnsureId(connection), isAuthenticated);
+
+                    MySqlDataAdapter da = new MySqlDataAdapter(
+                        "SELECT * FROM my_aspnet_Profiles WHERE userId=@id", connection);
+                    da.SelectCommand.Parameters.AddWithValue("@id", userId);
+                    MySqlCommandBuilder cb =new MySqlCommandBuilder(da);
+                    DataTable dt = new DataTable();
+                    da.Fill(dt);
+
+                    DataRow row;
+                    if (dt.Rows.Count == 0)
                     {
-                        connection.Open();
-
-                        // either create a new user or fetch the existing user id
-                        int userId = SchemaManager.CreateOrFetchUserId(connection, username, 
-                            app.EnsureId(connection), isAuthenticated);
-
-                        MySqlDataAdapter da = new MySqlDataAdapter(
-                            "SELECT * FROM my_aspnet_Profiles WHERE userId=@id", connection);
-                        da.SelectCommand.Parameters.AddWithValue("@id", userId);
-                        MySqlCommandBuilder cb =new MySqlCommandBuilder(da);
-                        DataTable dt = new DataTable();
-                        da.Fill(dt);
-
-                        DataRow row;
-                        if (dt.Rows.Count == 0)
-                        {
-                            row = dt.NewRow();
-                            dt.Rows.Add(row);
-                        }
-                        else
-                            row = dt.Rows[0];
-
-                        row["userId"] = userId;
-                        row["valueIndex"] = index;
-                        row["stringdata"] = stringData;
-                        row["binarydata"] = binaryData;
-
-                        count = da.Update(dt);
-                        if (count == 0)
-                            throw new Exception(Resources.ProfileUpdateFailed);
-                        ts.Complete();
+                        row = dt.NewRow();
+                        dt.Rows.Add(row);
                     }
-                }
-            }
-            catch (Exception ex)
-            {
-                throw new ProviderException(Resources.ProfileUpdateFailed, ex);
+                    else
+                        row = dt.Rows[0];
+
+                    row["userId"] = userId;
+                    row["valueIndex"] = index;
+                    row["stringdata"] = stringData;
+                    row["binarydata"] = binaryData;
+
+                    count = da.Update(dt);
+                    if (count == 0)
+                        throw new Exception(Resources.ProfileUpdateFailed);
+                    txn.Commit();
+                }
+                catch (Exception ex)
+                {
+                    if (txn != null)
+                        txn.Rollback();
+                    throw new ProviderException(Resources.ProfileUpdateFailed, ex);
+                }
             }
         }
 

=== modified file 'MySql.Web/Providers/Source/RoleProvider.cs'
--- a/MySql.Web/Providers/Source/RoleProvider.cs	2009-07-28 20:13:31 +0000
+++ b/MySql.Web/Providers/Source/RoleProvider.cs	2009-08-04 15:04:03 +0000
@@ -30,7 +30,6 @@
 using System.Web.Hosting;
 using System.Web.Security;
 using MySql.Data.MySqlClient;
-using System.Transactions;
 using System.Collections.Generic;
 using MySql.Web.Common;
 using MySql.Web.Properties;
@@ -168,39 +167,40 @@
                 }
             }
 
-            try
+            using (MySqlConnection connection = new MySqlConnection(connectionString))
             {
-                using (TransactionScope ts = new TransactionScope())
+                MySqlTransaction txn = null;
+                try
                 {
-                    using (MySqlConnection connection = new MySqlConnection(connectionString))
+                    connection.Open();
+                    txn = connection.BeginTransaction();
+                    MySqlCommand cmd = new MySqlCommand(
+                        "INSERT INTO my_aspnet_UsersInRoles VALUES(@userId, @roleId)", connection);
+                    cmd.Parameters.Add("@userId", MySqlDbType.Int32);
+                    cmd.Parameters.Add("@roleId", MySqlDbType.Int32);
+                    foreach (string username in usernames)
                     {
-                        connection.Open();
-                        MySqlCommand cmd = new MySqlCommand(
-                            "INSERT INTO my_aspnet_UsersInRoles VALUES(@userId, @roleId)", connection);
-                        cmd.Parameters.Add("@userId", MySqlDbType.Int32);
-                        cmd.Parameters.Add("@roleId", MySqlDbType.Int32);
-                        foreach (string username in usernames)
+                        // either create a new user or fetch the existing user id
+                        int userId = SchemaManager.CreateOrFetchUserId(connection,
+                            username, app.FetchId(connection), true);
+                        foreach (string rolename in rolenames)
                         {
-                            // either create a new user or fetch the existing user id
-                            int userId = SchemaManager.CreateOrFetchUserId(connection,
-                                username, app.FetchId(connection), true);
-                            foreach (string rolename in rolenames)
-                            {
-                                int roleId = GetRoleId(connection, rolename);
-                                cmd.Parameters[0].Value = userId;
-                                cmd.Parameters[1].Value = roleId;
-                                cmd.ExecuteNonQuery();
-                            }
+                            int roleId = GetRoleId(connection, rolename);
+                            cmd.Parameters[0].Value = userId;
+                            cmd.Parameters[1].Value = roleId;
+                            cmd.ExecuteNonQuery();
                         }
                     }
-                    ts.Complete();
-                }
-            }
-            catch (Exception ex)
-            {
-                if (WriteExceptionsToEventLog)
-                    WriteToEventLog(ex, "AddUsersToRoles");
-                throw;
+                    txn.Commit();
+                }
+                catch (Exception ex)
+                {
+                    if (txn != null)
+                        txn.Rollback();
+                    if (WriteExceptionsToEventLog)
+                        WriteToEventLog(ex, "AddUsersToRoles");
+                    throw;
+                }
             }
         }
 
@@ -244,40 +244,42 @@
         /// <returns>true if the role was successfully deleted; otherwise, false. </returns>
         public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)
         {
-            try
-            {
-                using (TransactionScope ts = new TransactionScope())
-                {
-                    using (MySqlConnection connection = new MySqlConnection(connectionString))
-                    {
-                        if (!(RoleExists(rolename)))
-                            throw new ProviderException(Resources.RoleNameNotFound);
-                        if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0)
-                            throw new ProviderException(Resources.CannotDeleteAPopulatedRole);
-
-                        connection.Open();
-                        // first delete all the user/role mappings with that roleid
-                        MySqlCommand cmd = new MySqlCommand(
-                            @"DELETE uir FROM my_aspnet_UsersInRoles uir JOIN 
-                            my_aspnet_Roles r ON uir.roleId=r.id 
-                            WHERE r.name LIKE @rolename AND r.applicationId=@appId", connection);
-                        cmd.Parameters.AddWithValue("@rolename", rolename);
-                        cmd.Parameters.AddWithValue("@appId", app.FetchId(connection));
-                        cmd.ExecuteNonQuery();
-
-                        // now delete the role itself
-                        cmd.CommandText = @"DELETE FROM my_aspnet_Roles WHERE name=@rolename 
-                            AND applicationId=@appId";
-                        cmd.ExecuteNonQuery();
-                    }
-                    ts.Complete();
-                }
-            }
-            catch (Exception ex)
-            {
-                if (WriteExceptionsToEventLog)
-                    WriteToEventLog(ex, "DeleteRole");
-                throw;
+            using (MySqlConnection connection = new MySqlConnection(connectionString))
+            {
+                MySqlTransaction txn = null;
+                try
+                {
+                    if (!(RoleExists(rolename)))
+                        throw new ProviderException(Resources.RoleNameNotFound);
+                    if (throwOnPopulatedRole && GetUsersInRole(rolename).Length > 0)
+                        throw new ProviderException(Resources.CannotDeleteAPopulatedRole);
+
+                    connection.Open();
+                    txn = connection.BeginTransaction();
+
+                    // first delete all the user/role mappings with that roleid
+                    MySqlCommand cmd = new MySqlCommand(
+                        @"DELETE uir FROM my_aspnet_UsersInRoles uir JOIN 
+                        my_aspnet_Roles r ON uir.roleId=r.id 
+                        WHERE r.name LIKE @rolename AND r.applicationId=@appId", connection);
+                    cmd.Parameters.AddWithValue("@rolename", rolename);
+                    cmd.Parameters.AddWithValue("@appId", app.FetchId(connection));
+                    cmd.ExecuteNonQuery();
+
+                    // now delete the role itself
+                    cmd.CommandText = @"DELETE FROM my_aspnet_Roles WHERE name=@rolename 
+                        AND applicationId=@appId";
+                    cmd.ExecuteNonQuery();
+                    txn.Commit();
+                }
+                catch (Exception ex)
+                {
+                    if (txn != null)
+                        txn.Rollback();
+                    if (WriteExceptionsToEventLog)
+                        WriteToEventLog(ex, "DeleteRole");
+                    throw;
+                }
             }
             return true;
         }
@@ -417,42 +419,44 @@
                 }
             }
 
-            try
+            using (MySqlConnection connection = new MySqlConnection(connectionString))
             {
-                using (TransactionScope ts = new TransactionScope())
+                MySqlTransaction txn = null;
+                try
                 {
-                    using (MySqlConnection connection = new MySqlConnection(connectionString))
+                    connection.Open();
+                    txn = connection.BeginTransaction();
+
+                    string sql = @"DELETE uir FROM my_aspnet_UsersInRoles uir
+                            JOIN my_aspnet_Users u ON uir.userId=u.id 
+                            JOIN my_aspnet_Roles r ON uir.roleId=r.id
+                            WHERE u.name LIKE @username AND r.name LIKE @rolename 
+                            AND u.applicationId=@appId AND r.applicationId=@appId";
+
+                    MySqlCommand cmd = new MySqlCommand(sql, connection);
+                    cmd.Parameters.Add("@username", MySqlDbType.VarChar, 255);
+                    cmd.Parameters.Add("@rolename", MySqlDbType.VarChar, 255);
+                    cmd.Parameters.AddWithValue("@appId", app.FetchId(connection));
+
+                    foreach (string username in usernames)
                     {
-                        connection.Open();
-                        string sql = @"DELETE uir FROM my_aspnet_UsersInRoles uir
-                                JOIN my_aspnet_Users u ON uir.userId=u.id 
-                                JOIN my_aspnet_Roles r ON uir.roleId=r.id
-                                WHERE u.name LIKE @username AND r.name LIKE @rolename 
-                                AND u.applicationId=@appId AND r.applicationId=@appId";
-
-                        MySqlCommand cmd = new MySqlCommand(sql, connection);
-                        cmd.Parameters.Add("@username", MySqlDbType.VarChar, 255);
-                        cmd.Parameters.Add("@rolename", MySqlDbType.VarChar, 255);
-                        cmd.Parameters.AddWithValue("@appId", app.FetchId(connection));
-
-                        foreach (string username in usernames)
+                        foreach (string rolename in rolenames)
                         {
-                            foreach (string rolename in rolenames)
-                            {
-                                cmd.Parameters[0].Value = username;
-                                cmd.Parameters[1].Value = rolename;
-                                cmd.ExecuteNonQuery();
-                            }
+                            cmd.Parameters[0].Value = username;
+                            cmd.Parameters[1].Value = rolename;
+                            cmd.ExecuteNonQuery();
                         }
                     }
-                    ts.Complete();
-                }
-            }
-            catch (MySqlException e)
-            {
-                if (WriteExceptionsToEventLog)
-                    WriteToEventLog(e, "RemoveUsersFromRoles");
-                throw;
+                    txn.Commit();
+                }
+                catch (MySqlException e)
+                {
+                    if (txn != null)
+                        txn.Rollback();
+                    if (WriteExceptionsToEventLog)
+                        WriteToEventLog(e, "RemoveUsersFromRoles");
+                    throw;
+                }
             }
         }
 


Attachment: [text/bzr-bundle] bzr/reggie.burnett@sun.com-20090804150403-f9fkevz9ngxyz69v.bundle
Thread
bzr commit into connector-net-5.2 branch (reggie.burnett:703) Bug#46375Reggie Burnett4 Aug