Luciano Evaristo Guerche

A brazilian geek interested in .NET technologies

  • Lots of new Israeli .Net Bloggers around!

    Mordy Shahar joins the Israeli .Net Bloggers crowed. Along with Ohad and Avner, he's also working at Magen with me. Keep your eyes open on this one. I hear he has a lot to say. Hey Mordy - not more hiding for you.
    I now have 22 Israeli .Net Bloggers listed on my site. Ah - I remember a time there were like 2 or three.
    What about you? Are you in Israel? wanna blog too? contact me and I'll tell you how to start quick and easy. The more knowledge we share - the more knowledge we get.
    [Via Roy Osherove, from Israel]

  • ADO -> ADO.NET migration

    If you are getting close to actually porting code, I'd recommend also reading Bill Vaughn's take on the subject, Migrating Code and Concepts from ADO "Classic" to ADO.NET. He comes at it from a more conceptual level - "What are your routines in ADO actually doing, and how can you get the same or better functionality in ADO.NET?" Between the two articles you should be able to get the conceptual underpinnings you'll need to get you started.

  • Whidbey Bloggers

    I intend to use this post to maintain a listing of Whidbey bloggers.  If you believe that you are blogging useful Whidbey content give me a ping and I'll add you to the list:

  • Reverse Enum Lookup

    Sometimes you may have the string name of an enumeration identifier, and want its enum type. For example, you write a enum identifier as a string to a file and want to read it back and obtain the original enumeration type. This takes place when you serialize a class to an XML file and deserialize it back using XmlSerializer.

  • Problem working with named transactions inside stored procedures

    I created the following two stored procedures using named transactions inside them

    /*
     **********************************************************
     */
    CREATE PROCEDURE #WorkingWithNamedTransactionsOne
    -- This procedure does not raise error
    AS
    DECLARE @ERROR bit
     
    PRINT 'Starting NamedTransactionOne'
    BEGIN TRANSACTION NamedTransactionOne
    SET @ERROR = 1
    PRINT 'NamedTransactionOne started'
     
    -- SOME TSQL statement here
     
    IF @@ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsOne_Finally
    END
     
    -- SOME TSQL statement here
     
    IF @@ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsOne_Finally
    END
     
    PRINT 'Committing NamedTransactionOne'
    COMMIT TRANSACTION NamedTransactionOne
    SET @ERROR = 0
    PRINT 'NamedTransactionOne committed'
     
     
    WorkingWithNamedTransactionsOne_Finally:
    IF @ERROR = 1
    BEGIN
        PRINT 'Rolling back NamedTransactionOne'
        ROLLBACK TRANSACTION NamedTransactionOne
        SET @ERROR = 0
        PRINT 'NamedTransactionOne rolled back'
    END
    RETURN
    GO
     
    /*
     **********************************************************
     */
    CREATE PROCEDURE #WorkingWithNamedTransactionsTwo
    -- This procedure raises error
    AS
    DECLARE @ERROR bit
     
    PRINT 'Starting NamedTransactionOne'
    BEGIN TRANSACTION NamedTransactionOne
    SET @ERROR = 1
    PRINT 'NamedTransactionOne started'
     
    -- SOME TSQL statement here
     
    IF @@ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsTwo_Finally
    END
     
    SELECT 1/0 AS [This might raise an error]
     
    IF @@ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsTwo_Finally
    END
     
    PRINT 'Committing NamedTransactionOne'
    COMMIT TRANSACTION NamedTransactionOne
    SET @ERROR = 0
    PRINT 'NamedTransactionOne committed'
     
     
    WorkingWithNamedTransactionsTwo_Finally:
    IF @ERROR = 1
    BEGIN
        PRINT 'Rolling back NamedTransactionOne'
        ROLLBACK TRANSACTION NamedTransactionOne
        SET @ERROR = 0
        PRINT 'NamedTransactionOne rolled back'
    END
    RETURN
    GO
    


    but when I execute them using the following script, an error occurred on the fourth EXECUTE statement

    /*
     **********************************************************
     */
    EXECUTE #WorkingWithNamedTransactionsOne
    GO
     
    EXECUTE #WorkingWithNamedTransactionsTwo
    GO
     
    BEGIN TRANSACTION
    EXECUTE #WorkingWithNamedTransactionsOne
    COMMIT TRANSACTION
    GO
     
    BEGIN TRANSACTION
    EXECUTE #WorkingWithNamedTransactionsTwo --ATTENTION: Server: Msg 6401, Level 16, State 1
     - Cannot roll back NamedTransactionOne. No transaction or savepoint of that name was found.
    COMMIT TRANSACTION
    GO
    


    How would you solve it? After dealing with this problem some time and doing some tests, I came out with the following new two stored procedures

    /*
     **********************************************************
     */
    CREATE PROCEDURE #WorkingWithNamedTransactionsAndSavepointsOne
    -- This procedure does not raise error
    AS
    DECLARE @ERROR int
     
    PRINT 'Starting NamedTransactionOne'
    BEGIN TRANSACTION NamedTransactionOne
    PRINT 'NamedTransactionOne started'
     
    PRINT 'Starting NamedSavepointOne'
    SAVE TRANSACTION NamedSavepointOne
    PRINT 'NamedSavepointOne started'
     
    -- SOME TSQL statement here
     
    SET @ERROR = @@ERROR
    IF @ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsAndSavepointsOne_Finally
    END
     
    -- SOME TSQL statement here
     
    SET @ERROR = @@ERROR
    IF @ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsAndSavepointsOne_Finally
    END
     
     
    WorkingWithNamedTransactionsAndSavepointsOne_Finally:
    IF @ERROR <> 0
    BEGIN
        PRINT 'Rolling back NamedSavepointOne'
        ROLLBACK TRANSACTION NamedSavepointOne
        PRINT 'NamedSavepointOne rolled back'
    END
     
    PRINT 'Committing NamedTransactionOne'
    COMMIT TRANSACTION NamedTransactionOne
    PRINT 'NamedTransactionOne committed'
     
    RETURN
    GO
     
    /*
     **********************************************************
     */
    CREATE PROCEDURE #WorkingWithNamedTransactionsAndSavepointsTwo
    -- This procedure raises error
    AS
    DECLARE @ERROR int
     
    PRINT 'Starting NamedTransactionOne'
    BEGIN TRANSACTION NamedTransactionOne
    PRINT 'NamedTransactionOne started'
     
    PRINT 'Starting NamedSavepointOne'
    SAVE TRANSACTION NamedSavepointOne
    PRINT 'NamedSavepointOne started'
     
    -- SOME TSQL statement here
     
    SET @ERROR = @@ERROR
    IF @ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsAndSavepointsTwo_Finally
    END
     
    SELECT 1/0 AS [This might raise an error]
     
    SET @ERROR = @@ERROR
    IF @ERROR <> 0
    BEGIN
        GOTO WorkingWithNamedTransactionsAndSavepointsTwo_Finally
    END
     
    WorkingWithNamedTransactionsAndSavepointsTwo_Finally:
    IF @ERROR <> 0
    BEGIN
        PRINT 'Rolling back NamedSavepointOne'
        ROLLBACK TRANSACTION NamedSavepointOne
        PRINT 'NamedSavepointOne rolled back'
    END
     
    PRINT 'Committing NamedTransactionOne'
    COMMIT TRANSACTION NamedTransactionOne
    PRINT 'NamedTransactionOne committed'
     
    RETURN
    GO
    


    Then I executed the new stored procedures again as follow, and no errors occurred

    /*
     **********************************************************
     */
    EXECUTE #WorkingWithNamedTransactionsAndSavepointsOne
    GO
     
    EXECUTE #WorkingWithNamedTransactionsAndSavepointsTwo
    GO
     
    BEGIN TRANSACTION
    EXECUTE #WorkingWithNamedTransactionsAndSavepointsOne
    COMMIT TRANSACTION
    GO
     
    BEGIN TRANSACTION
    EXECUTE #WorkingWithNamedTransactionsAndSavepointsTwo
    COMMIT TRANSACTION
    GO
    


    What do you think about it? If you came out with a different solution, let me know about.

  • Fotovision

    From the capable group at Vertigo Software (the same folks who produced the venerable IBuySpy and Quake II .NET) comes FotoVision, a suite of applications that allow you to organize and manipulate digital photos and share them on a web site. A full Windows Forms desktop client is provided, along with an ASP.NET web site that exposes some Web Services, and a Pocket PC application that leverages the .NET Compact Framework. Additionally, there are a number of good white papers that explain the architecture and technology behind the solutions. And if that isn’t enough, the full source code for all three applications is provided in Visual Basic .NET (included in the installation).

  • MSDN Magazine on the go...

    Scott found a cool .chm reader for the Pocket PC written by Peter Tewkesbury.  Since all of the current year's issues of MSDN Magazine are made available in CHM format, you can easily take multiple issues of the magazine with you on the train, on a plane, or wherever else you might go (though, like many people, I personally prefer the feel of a solid magazine that I can flip through and peruse at my leisure).  In addition, every year we release a compilation CD containing in CHM format every issue of MSDN Magazine ever printed, available for only the cost of s&h.