How To Avoid ASP.NET SqlServer Session To Interfer With The Ambient Transaction-Per-Request?

May 20, 2010

I am trying to use a transaction scope in a transaction-per-request pattern. So I have a http module that do (simplified):

private void Application_BeginRequest(object sender, EventArgs e)
{
var scope = new TransactionScope(TransactionScopeOption.RequiresNew);
PutScopeInHttpContext(scope);
}

private void Application_EndRequest(object sender, EventArgs e)
{
var scope = GetScopeFromHttpContext();
try
{
if (HttpContext.Current.Error == null)
{
scope.Complete();
}
}
finally
{
scope.Dispose();
}
}


Then, in my web.config, I have:

<httpModules>
<clear/>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
<add name="Profile" type="System.Web.Profile.ProfileModule"/>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="TransactionPerRequestWebModule" type="Acme.Web.TransactionPerRequestWebModule, Acme.Web"/>
</httpModules>
<sessionState mode="SQLServer" sqlConnectionString="Data Source=localhostSQLEXPRESS;Integrated Security=SSPI;" cookieless="false" timeout="360"/>


Now, at what seem like randomly rate, roughly 1 page out of ten gives me the following error:

[SqlException (0x80131904): Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +83
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
System.Data.SqlClient.SqlCommand.ExecuteReader() +89
System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +516

[HttpException (0x80004005): Unable to connect to SQL Server session database.]
System.Web.SessionState.SqlSessionStateStore.ThrowSqlConnectionException(SqlConnection conn, Exception e) +229
System.Web.SessionState.SqlSessionStateStore.DoGet(HttpContext context, String id, Boolean getExclusive, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +649
System.Web.SessionState.SqlSessionStateStore.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actionFlags) +48
System.Web.SessionState.SessionStateModule.GetSessionStateItem() +117
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +487
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +66
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155


What I (think I) understand is that the connection to the ASP.NET session database is sometimes enlisted in my business transaction, and I get this error when my business transaction is completing first.

There is a couple of problem with that:


I don't think the transaction for the session state should be the same as my business one. These are 2 separate concerns.
It makes the transaction automatically escalate to a distributed (MSDTC) one, which impacts my performance.

How do I decouple my business transaction from the ASP.NET session one?

View 1 Replies


Similar Messages:

Visual Studio :: How To Avoid Transaction Number Duplicated

Feb 16, 2010

I am New to VB.NET, Iam having a problem such as transaction numberDuplicatiion, Because so many users using a application, Some times transaction trnumber has been duplicatedIn my code i open LOCATION TABLE AND FETCH JOURNAL NUMBERAND INCREASE JOURNAL NUMBER WITH 1 AND THEN UPDATED.SOME TIMES JOURNAL NUMBER HAS BEEN DUPLICATED IN TRANSACTION FILE

View 1 Replies

State Management :: When To Use SQLServer Or StateServer Session Mode

Feb 13, 2011

Just wanted to know in which type of web application we can use out proc session state mode?

View 2 Replies

An Unhandled Exception Occurred During The Execution Of The Current Web Request - How To Avoid It

May 6, 2010

in local it works. when i load server, i got this error.

Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

Description:

An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Using themed css files requires a header control on the page. (e.g. <head runat="server" />).

[code]....

View 1 Replies

Build A Fully Customized Session State Mode Instead Of Using Inproc Or SQLServer?

Mar 4, 2011

Is it possible to build a fully customized Session State Mode instead of using Inproc or SQLServer?

View 1 Replies

State Management :: Using Global.asax To Set Session Variables Pulled From SQLServer?

Sep 3, 2010

I have a custom class that pulls user information from a SQL Server table. Now that I'm expanding the site from a single page to others. I want to shift the code to the Session_Start event so that the information is always loaded when the site is accessed. How do I call my custom code from global.asax since its script and not a class.

View 5 Replies

Flush Separate Castle ActiveRecord Transaction And Refresh Object In Another Transaction

Jun 15, 2010

I've got all of my ASP.NET requests wrapped in a Session and a Transaction that gets commited only at the very end of the request. At some point during execution of the request, I would like to insert an object and make it visible to other potential threads - i.e. split the insertion into a new transaction, commit that transaction, and move on. The reason is that the request in question hits an API that then chain hits another one of my pages (near-synchronously) to let me know that it processed, and thus double submits a transaction record, because the original request had not yet finished, and thus not committed the transaction record.

So I've tried wrapping the insertion code with a new SessionScope, TransactionScope(TransactionMode.New), combination of both, flushing everything manually, etc. However, when I call Refresh on the object I'm still getting the old object state. Here's some code sample for what I'm seeing:

Post outsidePost = Post.Find(id); // status of this post is Status.Old
using (TransactionScope transaction = new TransactionScope(TransactionMode.New))
{
Post p = Post.Find(id);
p.Status = Status.New; // new status set here
p.Update();
SessionScope.Current.Flush();
transaction.Flush();
transaction.VoteCommit();
}
outsidePost.Refresh();
// refresh doesn't get the new status, status is still Status.Old

View 1 Replies

C# - How To Avoid Session Timeout In Web.config

Mar 18, 2011

what should i write in web config file in asp.net so that my session time is extended. the exact location where should i place the code in web config

View 6 Replies

Avoid Session Hijacking For Web Applications?

Aug 18, 2010

I read about Session Hijacking articles and would like to some more information related to it. Currently my web application which is developed in ASP.NET , is using Cookieless =true mode for sessionstate. We are using HTTPS which is a secure connection which will reduce session hijacking. I know when we using Cookieless the session id is embedded in URL which can be dangerous sometimes if user pass this URL to somebody and other user will be able to log in if session is still alive. So just want to know is HTTPS is more than enough or i should do something to secure my web app.

View 4 Replies

Good Practice To Avoid Using Session State In MVC?

Mar 7, 2011

It's not explicitly written somewhere but I felt so after reading few blogs on ASP.NET MVC. Just got curious and thought of asking it here.

UPDATE: I'm not asking about memory/storage/RAM concerns on server. For them, there is a solution to store session out of process. I know that. I'm curious that, are there any scenarios where we had to use Session in WebForms but we can avoid it now in MVC taking benefit of the nice structured way offered by MVC?

View 6 Replies

Web Forms :: How To Avoid Session Timeout In Website

Oct 25, 2013

In my website, the session is expired after 5 minutes. I need to extend the seesion state to minimum 4 hours. Currently, in web.config file I used the following code.

<sessionstate cookieless="false" timeout="1440"></sessionstate>

But its expired after just 5 minutes.

View 1 Replies

HttpHandlers / Modules :: Avoid Session Timeout In HTTPHandler?

Oct 29, 2010

How do I avoid ASP.NET session timeout from a httphandler?

View 1 Replies

State Management :: Avoid Session Remove While Upgrade Web App?

Feb 8, 2011

If I change web.config or update dll files, all the current users in a web application lose their session and one may lost all their input.

How can I avoid this issue? How do you deal with this issue?

View 3 Replies

.NET Deployment: How To Avoid Losing Session State When Updating Code

Jan 8, 2010

How do you work-around the fact that sessions are dropped every time you deploy certain code files to an ASP.NET website? Sometimes we need to deploy a crucial fix in the middle of the day but don't want to boot off all our users for it.

View 3 Replies

Configuration :: Session Expired Very Fast / Avoid Change Database From MS Access To SQL?

Aug 9, 2010

I am currently using the brinkster hosting (Pro Package) but recently they change my hosting to the new one and after that I got an error for sometimes and my session also expired very fast. Below is the feedback from Brinkster.

Thank you for letting us know about your recent experience with your application. From what we are able to find regarding your application problems, they appear to be related to your ms access database. Due to limitations of ms access, you may want to consider updating the database running your website to mysql. A Mysql database is available to your account at no additional charge.

MS access begins to experience issues like database locks (which is what appears to be happening to your application) when there are more than 3 or 4 concurrent connections to the database for reads. MS access is also only able to have one write connection open at any given moment. MS access databases are more susceptible to corruption and data loss than database application built for large application use and Enterprise or corporate use.

When you were hosted on the previous server, your IIS application pool was getting reset many times per day. This action was in effect unlocking your ms access database from its locked state. After we moved you to the new system and raised your memory utilization limit, your application does not receive resets more than one or two times a week. I have lowered your memory utilization from 200 to 100 in an effort to have your application reset more often, unlocking your database if it has began to cause issues.

My question is, do i have a choice to avoid change my database from MS Access to MySQL? Is MS Access database really have such problem as they mension or somethingelse happen on their server?

View 7 Replies

State Management :: Unable To Serialize The Session State In 'StateServer' And 'SQLServer' Mode

Dec 12, 2010

I am new to .net 4.0 and am using EF Model and SessionState Mode=SqlServer and I am getting this error below:

Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same restriction applies if similar serialization is done by the custom session state store in 'Custom' mode.

I checked the stack trace and its complaining about

[assembly: global::System.Data.Objects.DataClasses.EdmSchemaAttribute()]
[assembly: global::System.Data.Objects.DataClasses.EdmRelationshipAttribute("PoplarGroveModel", "tblMenuRole", "tblMenu", global::System.Data.Metadata.Edm.RelationshipMultiplicity.Many, typeof(PoplarGroveDataModel.Menu), "tblRole",

[Code].....

I marked it as serializable but then it complains about System.Data.Objects.ObjectContext is not marked as serializable and hence throws the same error.

View 1 Replies

Web Forms :: 3.5 Error: Unable To Make The Session State Request To The Session State Server?

Dec 7, 2010

Have not run the ASP.NET Development Server for a while. Today I copied a production website to my workstation and ran it with VS 2008. The following error message popped up. What is the problem with the ASP.NET development Server on my workstation? The website on the Production server still ran okay.Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of KEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesaspnet_stateParametersAllowRemoteConnection.
If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '127.0.0.1' as the server name.

View 2 Replies

MVC :: Avoiding "ambient" Parameters In ActionLinks

Dec 10, 2010

I have a number of ActionLinks in my site's master page that link off to the various top level pages of my site. Some of these top level pages include an optional "page" parameter, which defaults to 1:

[Code]....

The ActionLink itself appears like:

[Code]....

I expect that the link should show as "/Latest", since no "page" argument is specified in the ActionLink. However, if I'm currently on a different page that has a page parameter (/Author/Person/5) then the ActionLink appears as "Latest/5"!

I've heard this behavior referred to as "ambient parameters", but I haven't seen any way of working around it. setting "page" to null in the ActionLink, but that's not a general solution - some pages have more than one parameter and they aren't always called page.

How do I create a link through MVC that does not include any inherited/ambient parameters?

View 1 Replies

Passing Session[] And Request[] To Methods In C#?

Apr 13, 2010

In C#, How do you pass the Session[] and Request[] objects to a method?I would like to use a method to parse out Session and Request paramaters for a .aspx page to reduce the size of my Page_Load method. I am passing quite a few variables, and need to support both POSTand GET methods. For most calls, not all variables are present, so I have to test every variable multiple ways, and the code gets long...This is what I am trying to do, but I can't seem to properly identify the Session and Request paramaters (this code will not compile, because the arrays are indexed by number)

static string getParam(
System.Web.SessionState.HttpSessionState[] Session,
System.Web.HttpRequest[] Request,
string id)

[code]...

View 2 Replies

HttpModule : Detect First Request In A Session?

Sep 2, 2010

I have written a HttpModule for our site which generally accepts requests and checks for specific file extensions as well as the value of a specific session variable. Is it possible to detect the first request in a session?

View 1 Replies

Avoid Concurrent Login (logout Former Login Session) In Membership

Jan 8, 2010

I am wondering how I can implement so that later login session logout former login session to avoid concurrent login. I know how to check whether the user is online (by Membership.IsOnline()) and logout the current user (by FormsAuthentication.SignOut()). But I don't know how to logout the previous login session.

View 2 Replies

Flash - Associate Session With Client / Request Based On Ip

Mar 18, 2010

In one web page we use a flash upload control but becouse a flash bug in the upload event the session is lost as its posted back with a new session.

We have tought of using a table with ip and old session id or a query string with the old session id in order to reassing it in the uploaded event...

Knowing the old session id how can i reassign it to the client? (In C#)

View 2 Replies

MVC Session Per Request Pattern And IHttpModule - Open An ISession

Jan 9, 2010

Im trying to make a solution like this [URL] Now the question is how do I filter the request, I only want to Open an ISession if the request is for an ASPNET MVC Action, not for *.gif, *.css etc. How should I handle this filtering?

View 3 Replies

State Management :: Session Or Request In Class Without Passing As Parameter

Sep 3, 2010

I'd like to be able to reference the asp.net objects Session, Request, from a procedure without passing them in as parameters all the time. Is there a way to do this. For example, now I have

[Code]....

I'd like to call it like this "ContextPT.GetSession()" and have GetSession know how to find the Session object. I know this does not seem like a big deal in this case, but I have reasons.

View 1 Replies

Persisting Session State Via Multiple Request Using JQuery $.ajax()?

Jan 25, 2011

just been trying to recieve the session value from multiple jquery ajax requests on the same domain name. i think i understand that each request is kind of a virtual browser request so the session is mutally exclusive to each request, but there must be a way some how, has anyone solved this. Basically this is what im trying to do:

I have tries using type: GET and POST but still no luck.

First request - Stores the product id in a session

[code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved