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

  • Home
  • SEARCH
  • 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 6390947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:36:41+00:00 2026-05-25T03:36:41+00:00

So I have this old code being used, that runs simple ExecuteNonQuery command for

  • 0

So I have this old code being used, that runs simple ExecuteNonQuery command for database calls. I’m using DbConnection, DbTransaction and other System.Data.Common commands.

I seem to get a lot of Null Reference errors whenever I use the function in certain parts of the project, though it seems fine in other parts. I think it has to do with opening connections manually or some problem with calling it, but I’m wondering if the function itself is badly designed originally (shouldn’t there be a way to fix any problems in the way it is called?)

I feel when transactions are involved, these null reference errors come up more often, I think the error I get is null exception at “_command = _db.GetStoredProcCommand(storedProcedure);” inside the following function. But that stored procedure does exist, so it makes no sense.

public List<OutputParameter> execute(String storedProcedure, StoredProcedureParameter[] sqlParameters)
{
  try
  {
      List<OutputParameter> outputParameters = new List<OutputParameter>();
      _command = _db.GetStoredProcCommand(storedProcedure);

    for (int x = 0; x < sqlParameters.GetLength(0); x++)
    {
      if (sqlParameters[x] != null)
      {
        StoredProcedureParameter sqlParameter = sqlParameters[x];
        String param = sqlParameter.ParameterName;

        DbType dbType = sqlParameter.DbType;
        object value = sqlParameter.Value;
        if (sqlParameter.IsOutputParam)
        {
          _db.AddOutParameter(_command, param, dbType, 32);

          OutputParameter outputParameter = new OutputParameter(param);
          outputParameters.Add(outputParameter);
        }
        else
          _db.AddInParameter(_command, param, dbType, value);
      }
    }
    if (_transaction == null)
      _db.ExecuteNonQuery(_command);
    else
      _db.ExecuteNonQuery(_command, _transaction);

    foreach (OutputParameter op in outputParameters)
    {
      op.ParameterValue = _db.GetParameterValue(_command, op.ParameterName);
    }

    return outputParameters;
  }
  catch (SqlException sqle)
  {
    throw new DataAccessException(sqle.ToString());
  }
  catch (Exception e)
  {
    throw new DataAccessException(e.ToString());
  }
}
  • 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-05-25T03:36:41+00:00Added an answer on May 25, 2026 at 3:36 am

    Your _command variable appears to be a field and as such a shared member.

    As such your code is very susceptible to multithreading issues (if two functions call this class with different stored procedures, what happens?).

    A Command should also be closed and disposed of properly, which is not happening in your code, not explicitly anyways.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have some code kicking around that uses this old internal Sun package for
I have this code in jQuery, that I want to reimplement with the prototype
I have a piece of C code that is used from a C++ function.
I have an application that receives information from a database, and is used to
I'm about to have to rewrite some rather old code using SQL Server's BULK
I'm reviewing my old algorithms notes and have come across this proof. It was
I have this string 'john smith~123 Street~Apt 4~New York~NY~12345' Using JavaScript, what is the
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
Possible Duplicate: Can someone Explain this jQuery code? I have posted this before, but
I have some queries being run in a java program that makes use of

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.