.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to rollback transaction in wcf method if CommunicationException occured?

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :WCF


I have a simple wcf-service (wsHttpBinding) hosted in IIS which inserts data into database and returns number of inserted records and collection of errors (such as foreign key problems while inserting the data).

int ProcessCustomers(Customer[] customers, out ErrorLog[] errorLog)
This is a implementation:
public int ProcessCustomers(Customer[] customers, out ErrorLog[] errorLog)
 using (var tran = new TransactionScope())
 //insert data into database
 return cnt;

 And i have a very simple wcf-client which invokes this method and trying to catch exceptions.

 int inserted = client.ProcessCustomer(customers, out errorLogs);
catch (TimeException timeEx)
 //write to log
catch (FaultException faultEx)
 //write to log
catch (CommunicationException commEx)
 //write to log
catch (Exception ex)
 //write to log

//close the proxy 

View Complete Post

More Related Resource Links

Doesn't restart sql server rollback uncommitted transaction?

hi, i executed a long-running sql in the management studio. The sql updates many rows and all updates are within a transaction. After runing 30 mins, the hard disk is full. That's because of the uncommitted updates. Then, i restarted the sql server because I thought after restarting, the uncommitted transaction is rollback and the occupied hard disk space is also released. But i found that the transaction is rollbacked but the hard disk space is not released. Why the hard disk space is not released? how can i release the disk space now? Thank you for your help.

Rollback Transaction or Rollback Work

Hi all, I run a delete statement,  but it deleted wrong rows that I need in my table. I didn't start with begin transaction statement, is there a way to bring these data back using any Rollback statement or any other ways? Thank you.  

WCF Async method inside a WCF transaction


Can WCF async methods be called  from within a WCF transaction?

Normally, one would only call synchronous methods from within a WCF transaction.

transaction does not rollback


I've just had a real WTF moment, so I'll try not to be too incoherent...

I have a transaction coded up to do inserts in header/detail tables.  I nested everything in a transaction, thinking that if there was a problem, the transaction would rollback and, while it would commit my new data, it would nevertheless leave the database in a consistent state.  But it seems to not have worked...

Here's the transaction:

		DECLARE	@DeliveryPointID	INT				= 1,
				@TrailerID			INT				= NULL,
				@LoadPercent		DECIMAL(8, 4)	= 100.0
		INSERT INTO dbo.Slips (DeliveryPointID, GrowerContractID, TrailerID, PackRequestID, GrossWeight, LoadPercent, ReceivedDate, VarietyID, Notes)
		VALUES (@DeliveryPointID, @ContractID, @TrailerID, @PackRequestID, @GrossWeight, @LoadPercent, @ReceivedDate, @VarietyID, @Notes)
		SELECT @SlipID = 

Transaction failed to rollback


I have a client which is running SQL 2005 Express on a Windows 2003 box. The system is very much barebones with extremely small storage space (10GB total!)

The other day I had done a column modification for them on one of their larger tables. Unknowingly, I was up against their threshold for diskspace and was unable to complete the transaction. I received the following:

Could not allocate space for object 'dbo.Tmp_jobresumes' in database '###' because the 'PRIMARY' filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.

Thereafter, the the table could not be found. Neither the original table name nor the tmp table name.This is a huge issue as I found out that they also do not have a backup of the database where I could start to restore our log files up until the point of failure.

I'm in a major pinch because the tables contains all of their assets for candidates (they are a staffing firm) over the past 7 years and I cannot seem to figure out how best to retrieve this information - in part due to the fact that I am reluctant to make any moves (i.e. restarting server, etc.) as I do not want to loose any change of recovery unless I know the implications fully. I know that the data is st

Nested transactions, rollback causes error "Transaction count after EXECUTE indicates that a COMMIT



I have a stored proc that does something that requires a transaction, and so I've put in the begin tran, commit, and rollback on error logic in it. That works as expected. But what if I now want to use the proc in the context of a larger transaction, such as calling it multiple times or doing other things as part of the same transaction? This seems impossible to achieve without either raising an error (throwing an exception) or having SQL Server do so on my behalf, rather unhelpfully.

For instance, I wanted to test a proc and reckoned a simple way to do so would be to start a transaction, execute the procedure, and roll back the transaction if the procedure didn't abort it:

begin transaction 
exec someProc
if XACT_STATE() = 1 rollback

This works if someProc doesn't encounter any errors (so it begins and commits a transaction and the transaction count is 1 at entry and exit of the proc), but crashes and burns if the procedure rolls back the transaction, producing SQL error

Msg 266, Level 16, State 2, Procedure ExecuteImport, Line 0
Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 1, current count = 0.

I don't understand why that is. To my mind, it is perfectly normal that the transaction count can go from any level at entry to ze

Rollback transaction for calling web services


Dear all,


I have the web form whcih processing several web services calls.

If one call failed, it will rollback transactions. But it cannot.

Due to the web services will complete for each call.

I am using sql connection and sql command.

Is it possible to do this??? 

Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing



We have Sharepoint 2007 SP1 databases on SQL Server 2005 SP3 x64. Users are uploading and viewing the documents with NO issues but we are frequently getting the below error in share point logs:

08/01/2010 08:21:33.11  w3wp.exe (0x0DA4)                        0x2168 Windows SharePoint Services    Database                       6f8g Unexpected Unexpected query execution failure, error code 266. Additional error information from SQL Server is included below. "Transaction count after EXECUTE indicates that a COMMIT or ROLLBACK TRANSACTION statement is missing. Previous count = 0, current count = 1." Query text (if available): "DECLARE @@S uniqueidentifier; DECLARE @@DocId uniqueidentifier; DECLARE @@Level tinyint; DECLARE @@DocUIVersion int; DECLARE @@DoclibRowId int; DECLARE @@iRet int;DECLARE @DN nvarchar(256); DECLARE @LN nvarchar(128); DECLARE @FU nvarchar(260); SET @@Level=2 SET @@DocUIVersion =1 SET @@DocId='9FA36FDF-00FF-4810-92CE-A5ED5671A0C9' SET @@S='6780CE0A-2C92-463D-B86D-D8ACBB72E065'; EXEC @@DoclibRowId = proc_GenerateNextId 'C145E0B3-9F7C-4E0F-9644-7DB0AEE53EDF','1E9F697F-4032

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

SQL Server Database Transaction

A transaction is a group of SQL commands executed together as a single component of work to be accomplished. If all of these commands succeed, then a transaction is committed - the changes to the data are made final. If any of the commands within a transaction fail, then the entire transaction is cancelled, or in SQL Server terms, the transaction will be rolled back.

Transactions are one of the things that keep your data safe, but they're not necessarily easy to understand. Here's some help:

Sys.Net.WebServiceFailedException: The server method '' failed with the following error:



Let's say we have 2 time consuming functions, aaa and aaa1 inside a aspx page.

        public static string aaa(int i)
            return i.ToString();

        public static string aaa1(int i)
            return i.ToString();



        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
        <span id="displayspan"></span>
        <br />
        <input type="button" value=

Jscript error: Object does not support property or method


 Hi, i have little knowledge on javascript but i need to use this code get from somewhere for a jquery to work.

I face this "Jscript runtime error: Object does not support property or method" whenever im trying to run this page.

In my experience, im get this error msg 9 out of 10 times i use javascript in my system.

Im using Microsoft Visual web developer 2008, i wonder if this is related to my problem, i not sure there is anything i need to add as reference or update anything.

But anyway, in short, i just couldn't use javascript code when using this development tool because of this sort of error.

Anyway, it happen that last time i tried use the same type of jquery code in another project and it seems to work well without an error.

But now when im try to use it again in this recent project i created, it come out with this error and i have no idea how to solve it even look through google and this forum.

It doesn't really seems like its the code problem itself although im not sure, because any javascript code just couldn't work.

So below is my code that i need to use.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src=&quo

Using CreateNewUserWizard SendingMail method to email me, not applicatnt.


I have staff area of my site I am protecting with forms authentication using c# and .Net 4.0. What I want to do is let the staff members register on the site but instead of the confermation email being sent to them I want it sent to me so I can go in and approve it. I have been trying to use the SendingMail method  but can not figure out how to get it to email me instead of the person that registered. I have searched around this site and find many topics on the SendingMail method but none seem to properly address my issue. Can anyone help me out?

Activation error occured while trying to get instance of type Database, key "DBName"


Im using Enterprise library 5.0
I have a scenario, where I have to access two different databases in my application.

Basically this application is a webservice,delployed on my local for testing purpose.
I'm trying to access this web method from diffent windows application, default connection works fine but the other database throw's exception.

Problem is only my defaultDatabase is works fine, if I change defaultDatabase="MYCON1" with "MYCON2" it works fine, if I try to access the other database which is not default, throws exception.

<dataConfiguration defaultDatabase="MYCON1" />
<add name="MYCON1" connectionString="Data Source=server1;Initial Catalog=dbName1;User Id=Username1;Password=password1;"

" />
<add name="MYCON2" connectionString="Data Source=Server2;Initial Catalog=dbName2;User Id=Username2;Password=password2;"
providerName="System.Data.SqlClient" />

Database myDB=EnterpriseLibraryContainer.Current.GetInstance<Database>(); --> works fine for the default database (MYCON1)

Database myDB=EnterpriseLibraryCo

Multiple web methods in one transaction


Hi everyone

Sorry I am kinda new in web services, so it may sound a bit newbish question.

We have a web service that comunicates with the database and exposes web methods that enables the application to access the database. Each method does only one operation (Insert, Update or Delete). What I need to do is create a transaction that will be consisted of multiple calls to the database, meaning multiple calls of more then one web methods. Can I do that? (I read that if the web method does not throw exception - or ContextUtil.SetAbort() is not called - the transaction will be commited automatically when the web method finishes executing, which I don't want to happen because I want to call another web method in the same transaction, and then manually commit the transaction)

Thank you in advance.

statement cannot appear outside of a method body


hi all,

  i am posting my vb.net problem .plz tell me how to resolve this :-

Dim conn As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
    'Dim mysqlconnection As New SqlConnection(conn)
    'If mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();
    'Dim mySqlcommand As New SqlCommand("select CategoryId,CategoryName from Categories", mysqlconnection)
    'Dim mySqlDataAdapter As New SqlDataAdapter(mySqlcommand)
    'Dim mydataSet As New DataSet()

    'if mysqlconnection.State=ConnectionState.closed Then mysqlconnection.Open();

i m getting 5 errors in this code

declaration expected in mySqlDataAdapter.Fill method; Gridview1.DataSource=ds; Gridview1.DataBind();

Question in Get method in C#


I got a recent working code from client.I see errors in the get methods when i compile , below are some place where the error happens.Can any one help me out?


Error 2 'System.Environment.NewLine.get': cannot explicitly call operator or accessor C:\Documents and Settings\shankar\My Documents\Visual Studio 2008\Projects\DKCLwin\DKCLwin\LocalizationAdmin.cs 150 170 DKCLwin

Error 2 'System.Environment.NewLine.get': cannot explicitly call operator or accessor C:\Documents and Settings\shankar\My Documents\Visual Studio 2008\Projects\DKCLwin\DKCLwin\LocalizationAdmin.cs 150 170

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend