Business layer wrapping user information and transactions?

Discussion in 'ASP .Net' started by Mark Baldwin, Jan 18, 2007.

  1. Mark Baldwin

    Mark Baldwin Guest

    I have an application with both Windows Forms and ASP.NET front ends and
    uses both integrated web security and a security database. The problem I
    have is that I need to syncronize these security databases.

    The web front end uses ASP membership with the SQL provider, the database is
    moved to the SQL Server instead of the SQL Express datafile.

    The Windows Forms app uses tables such as "users" within the database.

    If I add a user on the website, I need also to add a user to the database
    "users" table.

    To achieve this I write a business layer component that wraps both the
    security data tables and the ASP.NET membership functions. So for instance,
    to delete a user...

    [DataObjectMethod(DataObjectMethodType.Delete, true)]
    static public void Delete(string UserName)
    {
    // delete user from internal database table "users"
    usersTableAdapter UserTableAdapter = new usersTableAdapter();
    int rowsAffected = UserTableAdapter.DeleteByName(UserName);

    // delete user from ASP.NET membership database
    Membership.DeleteUser(UserName, true);
    }

    The question is how do I get these two functions into a transaction so that
    if the deletion for the ASP.NET member fails, the delete on the internal
    database table is rolled back?

    --
    Best regards
    Mark
     
    Mark Baldwin, Jan 18, 2007
    #1
    1. Advertising

  2. One of the golden rules of software development is never, ever to hold the
    same data in more than one place. It's a maintenance nightmare.

    Is there no way you can get both front ends to use the same data?


    Petere

    "Mark Baldwin" <> wrote in message
    news:uHC$...
    >I have an application with both Windows Forms and ASP.NET front ends and
    >uses both integrated web security and a security database. The problem I
    >have is that I need to syncronize these security databases.
    >
    > The web front end uses ASP membership with the SQL provider, the database
    > is moved to the SQL Server instead of the SQL Express datafile.
    >
    > The Windows Forms app uses tables such as "users" within the database.
    >
    > If I add a user on the website, I need also to add a user to the database
    > "users" table.
    >
    > To achieve this I write a business layer component that wraps both the
    > security data tables and the ASP.NET membership functions. So for
    > instance, to delete a user...
    >
    > [DataObjectMethod(DataObjectMethodType.Delete, true)]
    > static public void Delete(string UserName)
    > {
    > // delete user from internal database table "users"
    > usersTableAdapter UserTableAdapter = new usersTableAdapter();
    > int rowsAffected = UserTableAdapter.DeleteByName(UserName);
    >
    > // delete user from ASP.NET membership database
    > Membership.DeleteUser(UserName, true);
    > }
    >
    > The question is how do I get these two functions into a transaction so
    > that if the deletion for the ASP.NET member fails, the delete on the
    > internal database table is rolled back?
    >
    > --
    > Best regards
    > Mark
    >
     
    Peter Bradley, Jan 18, 2007
    #2
    1. Advertising

  3. Mark Baldwin

    sloan Guest

    <<What he said>>

    I'd strongly recommend (with emphasis on the strongly) not trying to keep
    "sync" data.

    Using the Provider Model, you can create your ~own
    MyCustomMembershipProvider : MembershipProvider

    This will allow you to use your custom tables, and such.

    There's no reason why you can't use your MyCustomMembershipProvider from a
    Winforms.
    You'll just lose the "drag and drop" ability that you have in asp.net 2.0.

    See
    http://www.15seconds.com/issue/050216.htm

    "Peter Bradley" <> wrote in message
    news:...
    > One of the golden rules of software development is never, ever to hold the
    > same data in more than one place. It's a maintenance nightmare.
    >
    > Is there no way you can get both front ends to use the same data?
    >
    >
    > Petere
    >
    > "Mark Baldwin" <> wrote in message
    > news:uHC$...
    > >I have an application with both Windows Forms and ASP.NET front ends and
    > >uses both integrated web security and a security database. The problem I
    > >have is that I need to syncronize these security databases.
    > >
    > > The web front end uses ASP membership with the SQL provider, the

    database
    > > is moved to the SQL Server instead of the SQL Express datafile.
    > >
    > > The Windows Forms app uses tables such as "users" within the database.
    > >
    > > If I add a user on the website, I need also to add a user to the

    database
    > > "users" table.
    > >
    > > To achieve this I write a business layer component that wraps both the
    > > security data tables and the ASP.NET membership functions. So for
    > > instance, to delete a user...
    > >
    > > [DataObjectMethod(DataObjectMethodType.Delete, true)]
    > > static public void Delete(string UserName)
    > > {
    > > // delete user from internal database table "users"
    > > usersTableAdapter UserTableAdapter = new usersTableAdapter();
    > > int rowsAffected = UserTableAdapter.DeleteByName(UserName);
    > >
    > > // delete user from ASP.NET membership database
    > > Membership.DeleteUser(UserName, true);
    > > }
    > >
    > > The question is how do I get these two functions into a transaction so
    > > that if the deletion for the ASP.NET member fails, the delete on the
    > > internal database table is rolled back?
    > >
    > > --
    > > Best regards
    > > Mark
    > >

    >
    >
     
    sloan, Jan 18, 2007
    #3
  4. Mark Baldwin

    sloan Guest

    And see
    http://msdn2.microsoft.com/en-us/library/f1kyba5e(VS.80).aspx

    (read my other post first)


    "Peter Bradley" <> wrote in message
    news:...
    > One of the golden rules of software development is never, ever to hold the
    > same data in more than one place. It's a maintenance nightmare.
    >
    > Is there no way you can get both front ends to use the same data?
    >
    >
    > Petere
    >
    > "Mark Baldwin" <> wrote in message
    > news:uHC$...
    > >I have an application with both Windows Forms and ASP.NET front ends and
    > >uses both integrated web security and a security database. The problem I
    > >have is that I need to syncronize these security databases.
    > >
    > > The web front end uses ASP membership with the SQL provider, the

    database
    > > is moved to the SQL Server instead of the SQL Express datafile.
    > >
    > > The Windows Forms app uses tables such as "users" within the database.
    > >
    > > If I add a user on the website, I need also to add a user to the

    database
    > > "users" table.
    > >
    > > To achieve this I write a business layer component that wraps both the
    > > security data tables and the ASP.NET membership functions. So for
    > > instance, to delete a user...
    > >
    > > [DataObjectMethod(DataObjectMethodType.Delete, true)]
    > > static public void Delete(string UserName)
    > > {
    > > // delete user from internal database table "users"
    > > usersTableAdapter UserTableAdapter = new usersTableAdapter();
    > > int rowsAffected = UserTableAdapter.DeleteByName(UserName);
    > >
    > > // delete user from ASP.NET membership database
    > > Membership.DeleteUser(UserName, true);
    > > }
    > >
    > > The question is how do I get these two functions into a transaction so
    > > that if the deletion for the ASP.NET member fails, the delete on the
    > > internal database table is rolled back?
    > >
    > > --
    > > Best regards
    > > Mark
    > >

    >
    >
     
    sloan, Jan 18, 2007
    #4
  5. Hello Mark,

    As Peter and sloan have suggested, you can build a custom provider to do
    the work. Or if you want to manage such synchronized database updating, you
    can use the ADO.NET's Transaction(for updating in single database). Or if
    the tables are in different database, you can consider using classes in
    System.Transacdtions namespace to perform multi-database transaction.

    In addition, for ASP.NET SQL Membership &Role provider(and its API), you
    can feel free to use it in non-asp.net application also(winform or console
    application). What you need to do is simply copy those configuration about
    ASP.NET membership & role(from your web application's web.config file to
    your non-ASP.NET application's app.config file). Here is a blog article
    I've ever writen to demonstrate this:

    #Manage database of ASP.NET 2.0 Membership & Role services in non-ASP.NET
    context
    http://blogs.msdn.com/msdnts/archive/2006/12/16/asp-net-2-0-membership-role-
    management-out-of-asp-net-context.aspx

    Thus, you can let your winform application use the same API and access the
    same membershp &role data as the ASP.NET application.

    If you have any other specific question, please feel free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Jan 19, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. et
    Replies:
    2
    Views:
    1,942
  2. dan
    Replies:
    25
    Views:
    1,368
    Uncle Bob (Robert C. Martin)
    Oct 28, 2003
  3. Universe
    Replies:
    1
    Views:
    488
    Universe
    Oct 24, 2003
  4. java-john
    Replies:
    0
    Views:
    543
    java-john
    Mar 23, 2006
  5. Dhananjay
    Replies:
    1
    Views:
    1,164
    sloan
    Dec 18, 2006
Loading...

Share This Page