Hi We've tried to add a new user and then assign him to Users Role:

DataContext.Current.Session.BeginTransaction();

                user = DataContext.Current.Session.CreateObject<User>(username);
                user.Name = username;
                user.SetPassword(password, DataObjects.NET.Security.HashingMethod.SHA1);
                user.Email = email;
                user.PasswordQuestion = passwordQuestion;
                user.PasswordAnswer = passwordAnswer;
                user.CreationDate = DateTime.Now;
                user.Active = active;

                DataContext.Current.Session.Commit();

                if (!user.Roles.Contains(DataContext.Current.Session.SystemObjects.UsersRole))
                {
                    DataContext.Current.Session.BeginTransaction();

                    user.Roles.Add(DataContext.Current.Session.SystemObjects.UsersRole);

                    DataContext.Current.Session.Commit();
                }

And during second commit we get a command timeout exception.

But the most interesting thing that everything works fine when application is deployed on WindowsServer 2003+IIS6. The problem reproduced only on WindowsServer2008 or Vista + II7.

We haven't opened any transaction before this call. A User class is inherited from StdUser.

Have someone any ideas?

Thanks in advance!

asked Sep 30 '10 at 12:13

Denis's gravatar image

Denis
7225

edited Oct 17 '10 at 23:54

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412


3 Answers:

The question is closed. It was error in domain creation. One transaction wasn't committed. But still it's unclear for me why error is reproduced only on IIS7...

Anyway thank you for great support!

answered Oct 01 '10 at 07:12

Denis's gravatar image

Denis
7225

edited Oct 01 '10 at 07:13

Glad to hear that you figured this out!

(Oct 01 '10 at 07:27) Alex Ustinov Alex%20Ustinov's gravatar image

And few remarks: Uncommitted transactions are very probable reason of such kind of locking issues. So reducing overall transaction count in conjunction with proper try/catch handling would significantly improve both application stability and performance.

Regarding IIS: Do you use DataContext from our DoPetShop sample? As far as I remember this DataContext performs transaction handling and in addition it uses some hacks to ensure whole request reprocessing in the case of e.g. deadlock. These hacks most likely are not operable under IIS7. And this would be a reason.

(Oct 01 '10 at 07:35) Alex Ustinov Alex%20Ustinov's gravatar image

That is definitely strange. But I think that you can try to resolve the issue via handling all actions in a single transaction. Something like this:

try {
  DataContext.Current.Session.BeginTransaction();
  // All business logic here
  DataContext.Current.Session.Commit();
}
catch {
  DataContext.Current.Session.Rollback();
}

I think this would help because it will eliminate creating implicit transactions during at least accessing user.Roles property and subsequent Contains call.

Most probably you've run into locking issue and reducing amount of active transactions will reduce such kind of errors probability.

answered Sep 30 '10 at 13:01

Alex%20Ustinov's gravatar image

Alex Ustinov
2484

edited Sep 30 '10 at 13:06

Hi Alex, Thanks for you quick reaction.

But unfortunately I tried to do as you said, and in this case I got error on both environments.

Server Error in '/' Application.

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.

Source Error:

Line 296: if (!user.Roles.Contains(DataContext.Current.Session.SystemObjects.UsersRole)) Line 297: { Line 298: user.Roles.Add(DataContext.Current.Session.SystemObjects.UsersRole); Line 299: } Line 300:

Source File: E:\Sources\iCandySoftware\Foundation\Com.Dynarics.Foundation\Core\User.cs Line: 298

Stack Trace:

[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.] DataObjects.NET.Session.InnerPersistObjects(Key[] keys, Boolean withExternalFields) +2943 DataObjects.NET.Session.Persist() +135 DataObjects.NET.Transaction.Commit() +331

[TransactionAbortedException: Transaction aborted. Inner exception: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.] DataObjects.NET.Transaction.Commit() +452 DataObjects.NET.Session.Commit() +21 Com.Dynarics.Foundation.Core.User.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean active, Boolean checkEmailDuplicity) in E:\Sources\iCandySoftware\Foundation\Com.Dynarics.Foundation\Core\User.cs:298 BINN.Utilities.Business.CreateUser(String email) in E:\Sources\iCandySoftware\BINN\Utilities\Business.cs:467 BINN.Templates.BINN.Controls.BBPEmployee.CreatePerson() in E:\Sources\iCandySoftware\BINN\Templates\BINN\Controls\BBPDashboard\BBPEmployee.ascx.cs:483 BINN.Templates.BINN.Controls.BBPEmployee.CreateBU(Boolean& isNewBU) in E:\Sources\iCandySoftware\BINN\Templates\BINN\Controls\BBPDashboard\BBPEmployee.ascx.cs:460 BINN.Templates.BINN.Controls.BBPEmployee.Apply_click(Object sender, EventArgs e) in E:\Sources\iCandySoftware\BINN\Templates\BINN\Controls\BBPDashboard\BBPEmployee.ascx.cs:159 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

answered Oct 01 '10 at 05:44

Denis's gravatar image

Denis
7225

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA