Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8097645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:49:37+00:00 2026-06-05T21:49:37+00:00

The issue is that VS2010 Code Analysis is returning two CA2000 warnings for a

  • 0

The issue is that VS2010 Code Analysis is returning two CA2000 warnings for a particular function. I haven’t been successful at reproducing the warnings with a smaller block of code, so I’ve posted the original function in it’s entirety.

public int SaveTransaction( Transaction tx, UserAccount account ) {

        if ( tx == null ) {
            throw new ArgumentNullException( "tx" );
        }

        if ( account == null ) {
            throw new ArgumentNullException( "account" );
        }

        bool isRefund = tx.TransactionType == LevelUpTransaction.TransactionTypes.Refund;

        int pnRef = 0;

        using ( SqlConnection conn = new SqlConnection( DatabaseConfiguration.ConnectionString ) ) {

            using ( SqlCommand cmd = new SqlCommand( "dbo.SaveTransaction", conn ) ) {

                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add( "@InvoiceId", SqlDbType.VarChar, 100 ).Value = tx.InvoiceNumber;
                cmd.Parameters.Add( "@TxStartDate", SqlDbType.DateTime ).Value = tx.TransactionBeginDate;
                cmd.Parameters.Add( "@AuthDate", SqlDbType.DateTime ).Value = tx.AuthenticationDate;
                cmd.Parameters.Add( "@MerchantKey", SqlDbType.Int ).Value = account.MerchantKey;
                cmd.Parameters.Add( "@UserName", SqlDbType.Char, 25 ).Value = account.UserName;
                cmd.Parameters.Add( "@RegisterNumber", SqlDbType.Char, 10 ).Value = tx.RegisterNumber;
                cmd.Parameters.Add( "@ResellerKey", SqlDbType.Int ).Value = account.ResellerKey;
                cmd.Parameters.Add( "@TxEndDate", SqlDbType.DateTime ).Value = tx.TransactionEndDate;
                cmd.Parameters.Add( "@IpAddress", SqlDbType.VarChar, 15 ).Value = account.IPAddress;
                cmd.Parameters.Add( "@CustomerId", SqlDbType.VarChar, 50 ).Value = tx.CustomerId;
                cmd.Parameters.Add( "@TransactionId", SqlDbType.VarChar, 50 ).Value = tx.TransactionId;
                cmd.Parameters.Add( "@ProcStartDate", SqlDbType.DateTime ).Value = tx.ProcessorBeginDate;
                cmd.Parameters.Add( "@ProcEndDate", SqlDbType.DateTime ).Value = tx.ProcessorEndDate;
                cmd.Parameters.Add( "@AuthAmount", SqlDbType.Money ).Value = StringParser.ParseDecimal( tx.OriginalAmount );
                cmd.Parameters.Add( "@ResultCode", SqlDbType.VarChar, 50 ).Value = tx.ResultCode;
                cmd.Parameters.Add( "@ResultMessage", SqlDbType.VarChar, 150 ).Value = tx.ResultMessage;
                cmd.Parameters.Add( "@PONumber", SqlDbType.VarChar, 100 ).Value = tx.PurchaseOrderNumber;
                cmd.Parameters.Add( "@TaxAmount", SqlDbType.Money ).Value = StringParser.ParseDecimal( tx.TaxAmount );
                cmd.Parameters.Add( "@Refund", SqlDbType.Bit ).Value = isRefund;

                if ( tx.Order != null ) {
                    cmd.Parameters.Add( "@HostDate", SqlDbType.VarChar, 50 ).Value = tx.Order.HostTime.ToString();
                    cmd.Parameters.Add( "@ApprovalCode", SqlDbType.VarChar, 50 ).Value = tx.Order.TransactionId.ToString( CultureInfo.InvariantCulture );
                    cmd.Parameters.Add( "@NameOnCard", SqlDbType.VarChar, 200 ).Value = tx.Order.UserFirstName + " " + tx.Order.UserLastNameInitial;
                    cmd.Parameters.Add( "@TipAmount", SqlDbType.Money ).Value = StringParser.ParseDecimal( tx.Order.Tip.FormattedAmount );
                    cmd.Parameters.Add( "@TotalAmount", SqlDbType.Money ).Value = StringParser.ParseDecimal( tx.Order.TotalAmount.FormattedAmount );
                    cmd.Parameters.Add( "@DiscountAmount", SqlDbType.Money ).Value = StringParser.ParseDecimal( tx.Order.CreditAmount.FormattedAmount );
                }

                else  {
                    cmd.Parameters.Add( "@NameOnCard", SqlDbType.VarChar, 200 ).Value = DBNull.Value;
                    cmd.Parameters.Add( "@HostDate", SqlDbType.VarChar, 50 ).Value = DBNull.Value;
                    cmd.Parameters.Add( "@ApprovalCode", SqlDbType.VarChar, 50 ).Value = DBNull.Value;
                    cmd.Parameters.Add( "@TipAmount", SqlDbType.Money ).Value = 0;
                    cmd.Parameters.Add( "@TotalAmount", SqlDbType.Money ).Value = 0;
                    cmd.Parameters.Add( "@DiscountAmount", SqlDbType.Money ).Value = 0;
                }

                if ( isRefund ) {
                    cmd.Parameters.Add( "@OriginalPnRef", SqlDbType.Int ).Value = tx.OriginalToken;
                }

                conn.Open();

                using ( SqlDataReader dr = cmd.ExecuteReader() ) {

                    while ( dr.Read() ) {
                        pnRef = SqlNull.Integer( dr["TRX_HD_Key"] );
                    }
                }
            }

        }

        return pnRef;
    }

The two CA2000 warnings pertain to the using statements containing the SqlConnection and SqlCommand.

I can’t find any issues in the code itself, but I have found that commenting out lines at random will make the errors go away. For instance, commenting out the three money fields being set to 0 in the else block will remove the warnings. Conversely, commenting out just the three lines with DBNull.Value at the end will remove the error too. I can’t make sense of the results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:49:38+00:00Added an answer on June 5, 2026 at 9:49 pm

    This has been reported on Microsoft Connect as a possible bug in the analyzer. Apparently, if a using statement contains a lot of code this message is reported erroneously.

    It can be suppressed with:

    [System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Reliability", "CA2000:Dispose objects before losing scope" )]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There is an issue that I cannot solve, I've been looking a lot in
I'm running a weird issue here. I have code that makes jquery ajax calls
I've got an issue involving a website that I have been using VS 2008
So I have an issue that I'm not 100% sure on how to solve.
I have an issue that (I think) might have to do with scope, but
I have an issue that is driving me nuts and hoping someone can help.
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
I am having an issue that I can't seem to figure out. Hopefully somebody
I have an issue that seems like very flaky behavour, is this a problem
I have an issue that looks like a race condition with a webview callback

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.