transaction scope gets aborted often - c#

my transaction scope gets aborted often
my problem behind it :
when opening multiple transaction scope with different classes ,we face the error of transaction aborted,each and every class is nested and in the methods the transaction scope is initalized,but the method where the transaction scope declared is not called,but giving timeout and transaction scope gets aborted repeatedly.
My stack trace is as follows :
System.Transactions.TransactionAbortedException was caught
HResult=-2146233087 Message=The transaction has aborted.
Source=System.Transactions
StackTrace:
at System.Transactions.TransactionStatePromotedAborted.CreateAbortingClone(InternalTransaction tx)
at System.Transactions.DependentTransaction..ctor(IsolationLevel isoLevel, InternalTransaction internalTransaction, Boolean blocking)
at System.Transactions.Transaction.DependentClone(DependentCloneOption cloneOption)
at System.Transactions.TransactionScope.SetCurrent(Transaction newCurrent)
at System.Transactions.TransactionScope..ctor(TransactionScopeOption scopeOption)
at TrapError.ErrorDescription..ctor()
at QueryRecordsets.FetchRecordsets..ctor()
InnerException: System.TimeoutException
HResult=-2146233083
Message=Transaction Timeout
InnerException:
while analyzing error description it has the following info :
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 10/30/2013 9:19:31 AM
Event time (UTC): 10/30/2013 3:49:31 AM
Event ID: 057d425ae7424adbb9a021d856f0d3e0
Event sequence: 14
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/1/ROOT/eSmartDotNet-2-130275784247371995
Trust level: Full
Application Virtual Path: /eSmartDotNet
Application Path: I:\Rafiq\29-10-2013\Source Code Esmart Application\
Machine name: WINSERVER2012
Process information:
Process ID: 4908
Process name: w3wp.exe
Account name: IIS APPPOOL\DefaultAppPool
Exception information:
Exception type: HttpUnhandledException
Exception message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
The transaction has aborted.
at QueryRecordsets.FetchRecordsets..ctor()
at ASP.logincheck_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in I:\Rafiq\29-10-2013\Source Code Esmart Application\LoginCheck.aspx:line 42
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Transaction Timeout
Request information:
Request URL: http://localhost/eSmartDotNet/LoginCheck.aspx
Request path: /eSmartDotNet/LoginCheck.aspx
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\DefaultAppPool
Thread information:
Thread ID: 33
Thread account name: IIS APPPOOL\DefaultAppPool
Is impersonating: False
Stack trace: at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I'm not sure that TransactionScope will work on Oracle. My gut feel is that it is reliant on MS technologies like MS Distributed Transaction Coordinator (MSDTC). This seems to be confirmed by the MSDN documentation on the System.Transactions namespace where it states (my emphasis indicating MS technologies);
The System.Transactions infrastructure makes transactional programming
simple and efficient throughout the platform by supporting
transactions initiated in SQL Server, ADO.NET, MSMQ, and the Microsoft
Distributed Transaction Coordinator (MSDTC). It provides both an
explicit programming model based on the Transaction class, as well as
an implicit programming model using the TransactionScope class, in
which transactions are automatically managed by the infrastructure.
There are also a bunch of SO posts that seem to indicate they had issues getting it working with Oracle also;
Using TransactionScope with System.Data.OracleClient - TransactionAbortedException
Problems with TransactionScope and Oracle
Transaction Scope in Oracle with ASP.NET
The last link seems to indicate an Oracle specific DTC, but still doesn't offer much hope. You may need to look at other alternatives for handling transactions other than TransactionScope.

Related

How do i fix this error in WCF services?

I am currently attempting to use WCF services to input data into a database,
I have been following the steps of this tutorial: http://www.c-sharpcorner.com/UploadFile/rohatash/inserting-data-into-database-using-wcf-service/
and I have reached the end of it successfully:
enter image description here
however, when I press the button, data does not get put into the database; instead this message pops up:
Server Error in '/' Application.
The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.
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.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.
Source Error:
Line 146:
Line 147: public string InsertUserDetails(WebAppTest2.ServiceReference1.UserDetails userInfo) {
Line 148: return base.Channel.InsertUserDetails(userInfo);
Line 149: }
Line 150:
Source File: c:\users\mauro-buhagiarjl(848\documents\visual studio 2015\Projects\WebAppTest2\WebAppTest2\Service References\ServiceReference1\Reference.cs    Line: 148
Stack Trace:
[FaultException: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +153
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
WebAppTest2.ServiceReference1.IService1.InsertUserDetails(UserDetails userInfo) +0
WebAppTest2.ServiceReference1.Service1Client.InsertUserDetails(UserDetails userInfo) in c:\users\mauro-buhagiarjl(848\documents\visual studio 2015\Projects\WebAppTest2\WebAppTest2\Service References\ServiceReference1\Reference.cs:148
WebAppTest2.WebFormTest.Button1_Click(Object sender, EventArgs e) in c:\users\mauro-buhagiarjl(848\documents\visual studio 2015\Projects\WebAppTest2\WebAppTest2\WebFormTest.aspx.cs:27
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9712582
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1637.0
Any Ideas to where this message originates from?

Website loses connection to database sporadically

I've been struggling with this error for just over a month now and can't get it figured out.
Background/Architecture:
MVC 4 application
NHibernate
FluentNHibernate
SQL Server 2008 R2
Azure website
Sporadically throughout the day, my views are throwing errors because when they try to read/display properties on my objects, it says:
NHibernate.Exceptions.GenericADOException: could not initialize a
collection: [WrestleStat.BL.School.Schedule#54][SQL: SELECT
...(removed to keep this short)....] --->
System.Data.SqlClient.SqlException: Timeout expired. The timeout
period elapsed prior to completion of the operation or the server is
not responding. This failure occurred while attempting to connect to
the routing destination. The duration spent while attempting to
connect to the original server was - [Pre-Login] initialization=3;
handshake=23; [Login] initialization=0; authentication=0; [Post-Login]
complete=1; ---> System.ComponentModel.Win32Exception: The wait
operation timed out
--- End of inner exception stack trace --- at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection, Action`1 wrapCloseInAction) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject
stateObj, UInt32 error) at
System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() at
System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() at
System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() at
System.Data.SqlClient.TdsParserStateObject.TryReadByteArray(Byte[]
buff, Int32 offset, Int32 len, Int32& totalRead) at
System.Data.SqlClient.TdsParserStateObjec
2 weeks ago, I was running my website on AppHarbor, and I thought it was because I was on their "basic" (free) plan. The problem seemed to go away if I'd up my worker threads from 1 to 2. Because of that, I decided to switch over to Azure (I was going to anyway, but not this early). Since the switchover to Azure, the problem has not gone away.
I get approximately a dozen of these errors per day on the site. It appears as though that the errors always occur when the razor views are trying to access properties of an object that it's trying to read/display, as opposed to throwing the error inside the controller trying to retrieve the data. Maybe it has something to do with the lazy loading??? But why would that matter, why would the connection be lost in that extremely short timeframe from retrieving the data, then presenting it on the page?
I'm at a loss on how to debug this issue, because it obviously never happens in my development environment. I'm going to switch over to Dapper eventually, but I'm not able to do/start that for at least another 3 months.
Any ideas here?
Edit: here's the website http://www.wrestlestats.com
These are transient errors normal in a cloud environment. You need to implement a retry logic/policy.
Check this answer: How do I add Retry Logic in NHibernate to handle Transient Failures in SQL Azure?

`Server Error in '/' Application. No such host is known

I am getting this error on one website which is deployed in IIS , when i browse from network system i am getting this error .
other websites are working fine
`Server Error in '/' Application.
No such host is known
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.Net.Sockets.SocketException: No such host is known
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SocketException (0x2af9): No such host is known]
System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6) +3192148
System.Net.Dns.GetHostEntry(String hostNameOrAddress) +8777246
_Default.Page_Load(Object sender, EventArgs e) +320
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178`enter code here`
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18055'`
What you have here is one unhanded exception when you call the Dns.GetHostEntry as seen on the stack trace, and on the clear message that you have.
Wrap this part of the code with try/catch and log the error on your system. If its critical for you to know the dns name, then you need to show an error page with further instructions.

Why am I only *randomly* getting "Validation of viewstate MAC failed" in a single server environment?

Yes, there are a million questions and threads on this particular error, with many well-documented solutions, which I will definitely try. But first I want to understand the problem for my particular situation/environment.
In my situation, this error seems to be entirely random. I will go weeks without seeing it, then one day I'll log into my site and get the error. Refresh the page, login again, and no problem. During these periods in between incidents, nothing particularly special has happened to the web server.
And that's the other thing, the error says "If this application is hosted by a Web Farm or cluster...", but it's not. It's just one single Windows Server 2008.
So, I understand the general solution is to add a set of static machine keys to the web.config file --- but why does this happen seemingly at random, and why does it happen to my site which is on a single Windows Server 2008 machine?
I'm using ASP.NET 4 and my site is a Web Application running on IIS.
Error Message:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Stack Trace:
[ViewStateException: Invalid viewstate.
Client IP: ##::##:##:##:##
Port: ##
Referer: http://myserver/login.aspx
Path: /login.aspx
User-Agent: Opera/9.80 (Windows NT 6.1; WOW64; U; en) Presto/2.10.289 Version/12.01
ViewState: /wEPDw...6OCX]
[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +235
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +274
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +241
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
System.Web.UI.Page.ProcessRequest() +78
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.login_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
From your log, I suggest you to check one thing - Did you connect any parameter from your user with the Viewstate that can be changed if the user is logged in/logged out? - or change for any other reason, e.g. because session is expired or changed.
This parameter can be different between the saved and the current Viewstate and this can break the page.
For example this code can do that:
ViewStateUserKey = CurrentUserCookie;
Or this one as it is:
ViewStateUserKey = User.Identity.Name
Also read this answer: https://stackoverflow.com/a/2551810/159270
This is similar:
ViewStateUserKey + shared hosting + ViewStateMac validation failure
And Some reference:
http://www.hanselman.com/blog/ViewStateUserKeyMakesViewStateMoreTamperresistant.aspx
http://msdn.microsoft.com/en-us/library/ms972969.aspx
The random errors are the nightmare of any developer.

NeatUpload issue uploading pdf and gif files on remote server

We've recently run into this issue whereby pdf and gif files will not upload successfully on our remote system test server. Other file formats such as .docx, .xls, .jpg work and all file types work in the development environment. Both servers are Windows Server 2008 R2 Standard, IIS7.5 and run an asp.net 4.0 web application.
On searching google I've seen some references to making sure to use .close() properly, which I think I do as this works for other file types and on dev. Also in terms of permissions to the app_data\NeatUpload_Temp folder, I've ensured that the running account has write access.
Here's some pseudo C# code: -
if(inputFile.HasFile)
{
//Get the uploaded content
byte[] fileBytes = ReadContentsFromUploadedFile(inputFile);
//Get the uploaded file name
string fileName = GetFileNameFromUploadedFile(inputFile);
//Get the MIME type
string mimeType = inputFile.ContentType;
//Create custom object and store doc in SharePoint via web service
inputFile.FileContent.Close();
}
And a snippet from the Web.config: -
<neatUpload xmlns="http://www.brettle.com/neatupload/config/2008" useHttpModule="true" maxNormalRequestLength="102400" maxRequestLength="102400" defaultStorageProvider="FilesystemUploadStorageProvider" defaultStateStoreProvider="InProcUploadStateStoreProvider">
<providers>
<add name="FilesystemUploadStorageProvider" type="Brettle.Web.NeatUpload.FilesystemUploadStorageProvider, Brettle.Web.NeatUpload"/>
<add name="InProcUploadStateStoreProvider" type="Brettle.Web.NeatUpload.InProcUploadStateStoreProvider, Brettle.Web.NeatUpload"/>
</providers>
</neatUpload>
Any help or direction much appreciated!
Stack trace below: -
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.IO.IOException: The process cannot access the file 'C:\inetpub\wwwroot\UWP_SIT\app_data\NeatUpload_Temp\5b25efcf6e9246c1b989640f623486c0.config' because it is being used by another process.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[IOException: The process cannot access the file 'C:\inetpub\wwwroot\UWP_SIT\app_data\NeatUpload_Temp\5b25efcf6e9246c1b989640f623486c0.config' because it is being used by another process.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12896359
System.IO.FileInfo.Delete() +183
Brettle.Web.NeatUpload.FilesystemUploadedFile.Dispose() +909
Brettle.Web.NeatUpload.FileControl.OnUnload(EventArgs e) +235
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +160
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +323
System.Web.UI.Page.UnloadRecursive(Boolean dispose) +24
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +11351550
System.Web.UI.Page.ProcessRequest() +269
System.Web.UI.Page.ProcessRequest(HttpContext context) +167
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +625
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
It looks like the web application doesn't have permission to save the files to the destination.
You should check the permissions in two places:
neatupload's temp upload directory (where the files go before their
transfers are complete) the destination directory (the location where
you move them to once they are complete)

Categories