Trasaction problem (work in C# but not VB.NET)?


I am building a unit test project and have tryed the transaction in C# like this:


            using (TransactionScope oTranScope = new TransactionScope())
                //work to be done

 This workes grate even when the databas operations is deep down in a object.

I have now moved on to imiplement this in a VB.NET project and the code for this is as fallows:


                Using scope As TransactionScope = New TransactionScope()

                    lUpdateStaffResult = maintenance.UpdateStaff(lUpdateStaffRequest)

                    Throw New Exception("test")
                End Using
            Catch ex As Exception
            End Try

Apperently you have to throw a exception with in the transactionScope, else the complete will be executed? This should work either way, no data should be written to the database but it is? I have executed in debug mode to see what’s really happens, the data is added but never removed?

I am running against the same database (MS SQL 2000) with both the c# and the The code is slightly more advance (communication between LogicLayer/webservices, ServiceLayer, busunessLayer,Data access layer and stored procedures) some of the Stored procedures uses MS SQL Transactions as well.

 Any idée why this won’t work?



11/9/2006 2:44:24 PM 16182 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 36

I am not very good at VB, I was hoping somebody else will reply to you. But does not look like.

What I see in your code is that you are using inside a try that's why the exception

Remove the using, but make sure you call Dispose or Close

My Blog
Please click on 'Mark as Answer' if this post answered your question!
11/10/2006 1:44:45 AM


I have now tryed the fallowing:


            scope = New TransactionScope()
            lUpdateStaffResult = maintenance.UpdateStaff(lUpdateStaffRequest)

 But this does not work? My test function looks like this:


    <DataSource("System.Data.SqlClient", "Data Source=X;Initial Catalog=X;User ID=X;Password=X", "personal", DataAccessMethod.Sequential)> <TestMethod()> _
    <AspNetDevelopmentServer("WSMaintenance", "X")> _
    Public Sub AddOneUser()
        Dim maintenance As New Maintenance()

        Dim lUpdateStaffRequest As UpdateStaffRequest
        Dim lUpdateStaffResult As UpdateStaffResult = Nothing

        Dim inactive As Boolean = False

        Dim scope As TransactionScope


            Assert.IsTrue(WebServiceHelper.TryUrlRedirection(maintenance, testContextInstance, "WSMaintenance"), "Web Service faild")

            lUpdateStaffRequest = New UpdateStaffRequest()

            Dim lSt(1) As UpdateStaffRequestStaff
            lSt(1) = New UpdateStaffRequestStaff()
            lSt(1).Name = TestContext.DataRow()("namn").ToString()
            lSt(1).ExternalStaffId = TestContext.DataRow()("externId").ToString()

            If (Integer.Parse(TestContext.DataRow()("inaktiv").ToString()) > 0) Then
                inactive = True
            End If

            lSt(1).Inactive = inactive
            lSt(1).StaffCategoryId = Integer.Parse(TestContext.DataRow()("personal_kategori_id").ToString()) '1 '10
            lSt(1).CivilRegistrationNumber = TestContext.DataRow()("personnr").ToString()
            lSt(1).Initials = TestContext.DataRow()("namn_kort").ToString()
            lSt(1).TelephoneNumber = TestContext.DataRow()("telefon").ToString()
            lSt(1).OtherInformation = TestContext.DataRow()("fritext").ToString()

            lUpdateStaffRequest.Staff = lSt

            lUpdateStaffRequest.Envelope = New EnvelopeType()
            lUpdateStaffRequest.Envelope.StartTime = DateTime.Now

                Using scope As TransactionScope = New TransactionScope()
                    lUpdateStaffResult = maintenance.UpdateStaff(lUpdateStaffRequest)
                    Throw New Exception("test")
                End Using
            Catch ex As Exception
            End Try

            Assert.IsNotNull(lUpdateStaffResult, "no returning value")
            Assert.AreEqual(True, validateEnvelope(lUpdateStaffResult.Envelope), "Envelope is not valid")

        End Try
    End Sub

The maintenance.UpdateStaff(lUpdateStaffRequest) is going to the webservice that drills deep nown in the diffrent layers that ends with a Stored Procedure in a MS SQL Server.

According to this: it should work? I have tryed to do similiar things with C#(but with out layers and Stored procceduures) and this worked fine. This most mean that the MS SQL server is setup properly.

Pleas help

11/10/2006 8:22:05 AM

Hey again!

I have med some test with regular VB.NET class librarys and a unit test project and this works fine. I have now created a webservice and a unitTest project against it, it simes like the trasaction is nor working over the webservice? is there any way to get this to work?

Else i will have to place my unit test on the service layer insted(one level down) and hope that the trasaction will work between layers?

11/10/2006 2:41:46 PM

Similar Artilces:

Sending SMS using or using or
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Type.GetType does not work in VB.NET but works in C#. VB.NET gurus Please help
Friends,   I am an experienced C# programmer who is working on a VB.NET project now. I am writing different methods covering the following functionalities 1) Take a datareader as input and return an arraylist of class object2) Take an xmlnode (received from a webservice) as input and return an arraylist of class object. The methods are generic methods which take datareader/xmlnode as first parameter and classname (string) as the second parameter. This way it will work trivially. The schema of class object matches with the input (datareader or xmlnode)In C# I used to do th...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

converting to from offered me some sample code when I signed up with them the only problem is the sample code is in but my page that they type all of their credit card into is <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage(""); } private String readHtmlPage(string url) { ...

.Net 2.0 Web application using is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one web application using which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So... vs vs
just out of curiousity which looks, acts most like java? i'm still learning trying to used to but it seems that it was easier to do some stuff with java. C# is Java++ in my opinion. If you have done C or Jave you will prefer C#.Mike Schellenberger - MCAD If you are looking for language similar to java go for J#. However most code samples you find on the net will be in VB.NET and C#....

Problem using vb object in
Hi guys, I am doing a c# project, and i am trying to add a custom control written by to my project. I get the following error when I drag-and-drop the control from my toolbox and build the project: Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0234: The type or namespace name 'CountryDropDown' does not exist in the class or namespace 'CountryDropDown.CountryDropDown' (are you miss...

what lang does everyone prefer? Thanks, Peter Iuvara, MCP It's a very famous debatable question in forums! I would say if you are from Java/C/C++, then C# would be easy to use for you. If you are from ASP/VB, then VB.NET would be easy for you! As long as if you follow CLS, then what ever the language you use, it's going to be the same for CLR!Sreedharhttp://www.w3coder.orgweblog I would agree with that ... just curious as to what user's on this forum predominantly code in?Thanks, Peter Iuvara, MCP I came from no real programming background, started i...

vb .net or c# .net
I currently develop websites using php but have been requested to develop a site using The question I have is for someone who knows php would it be better to transition to or Thanks, Fr. Robert C# -> There is a converter that will transition about 60% or more of your PHP code to C#. Plus C# is closer to PHP than VB.NET.Jason N. GaylordASPInsider and Microsoft MVP

VB.Net To C#.Net
Hello... Since Last from 1 year i had develope web application in using now i want to transfer from to so what should i do to transform to c# language any link or book related to me through i can easily understand and coding using c# in a short time... Thanks~ Mark As Answer If UseFull ~Kaushal. Hi, you can read the specifications of the language. You're already familiar with .NET and how to program in an OO manner thanks to your experience with The only thing you need to learn is the new syntax of C#. You can also convert parts of your v...

DropDownList SelectedIndex problem in C# (from working VB.NET)
Hello All, I've been diligently going through the examples in Scott Mitchell's "ASP Data Web Controls" book (I would recommend this work -- cleared up a lot of questions for me). All of the examples are in VB.NET and though I've been able to convert pretty much all of the examples so far into C# (my preferred language), there's one critical example that has me stumped. In Chapter 9, he demonstrates how to create a DataGrid containing a column with a DropDownList containing a foreign key to another table (using the pubs database, displaying the books table with FK to publishers n...

Help Me C# is working But Not working
Edited by SomeNewKid. Please post code between <code> and </code> tags. Pls, Help me, It is simple chat programe. My <IFRAME> src is calling the bellow event in C# it is working perfectly. private void Page_Load(object sender, System.EventArgs e) { string sDealer=""; string sWrite=""; if ( Session["Channel"] != null ) sDealer = Session["Channel"].ToString(); Response.Write( "<meta http-equiv=\"Refresh\"content=\"4\">" ); sWrite=MyModule.MyChat.GetAl...

Difference Between VB.Net And C#.Net
 hi friends,Please tell me the key difference between the Vb.Net And C#.Net..wheather supports operator overloading..Thanks & Regards,Pravin Kumar T.   Regards,Pravin Kumar T. pravin_thanusu:Please tell me the key difference between the Vb.Net And C#.Net.. Neither are ASP.NET so you probably want a different forum.  You'll also find your answers at JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.  >Please tell me the k...

Converting from to
Hello I have recently purchased VBGolds RawDataPrinter which should allow users to print directly to label printers on our network directly from a c# web form.  Unfortunately they only supply examples and I have need of c#.  The component has been installed on our web server.  This is some code that they have supplied as examples in   "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" >"Head1" runat="server&qu...

Web resources about - Trasaction problem (work in C# but not VB.NET)? -

Forecast: 30 Percent Of Cyber-Monday Trasactions Will Be Mobile
Using a mix of its own data and third party data, mobile ad personalization platform AppLovin is predicting that nearly 30 percent of Cyber Monday ...

Coins List - CryptoNerd
-BTC Bitcoin- First, strongest, most accepted, most mined, high volume market, a true currency -LTC Litecoin- Second only to BTC , faster than ...

► Acme Technologies
... and Web applications. Home Products Support Blog Acme Technologies' New iPhone Apps... CCAuthorize Customers: If your trasactions ...

About » Cyber Crimes Unit - Cyber Crimes Unit
Cyber Crimes Unit semper vigilavi semper secura Home About Anti-spam Policy Disclaimer Dmca Notice E-mail Policy External Links Policy Privacy ...

Did Iran just seize a Deep Web drug market?
All in all, Thursday may not have been the best day people for people who enjoy trafficking in illicit goods online.

How to Avoid Getting Scammed in Domaining
This is a complete guide on domain scammers that shows how to recognize and avoid scammers while trading domains. There are several popular scamming ...

Knights Templar Documentary - Legend Hunters - Ark of the Covenant - FactualTV
Knights Templar Documentary - Legend Hunters - Ark of the Covenant - FactualTV In this episode of Legend Hunters, we follow the team as they ...

Timothy B. Lee - Disruptive Economics - Forbes
Timothy B. Lee's stories. Disruptive Economics: I write about how technology shapes society

Financial Data Security Solutions & Protecting Trasaction Security From SafeNet Inc.
Providing financial data security and transaction security to the financial services industry with solutions from SafeNet.

Resources last updated: 11/21/2015 1:18:02 AM