public void BeginTransaction()
{
try
{
this._keepalive = true;
if (_oracleConnection.State != ConnectionState.Open)
_oracleConnection.Open();
//_oracleConnection.Autocommit = false;
this._transaction = this._oracleConnection.BeginTransaction(IsolationLevel.ReadCommitted);
}
catch (Exception ex)
{
_hasError = true;
_ErrorMessage = ex.Message + "::" + ex.StackTrace;
}
}
public void CommitTransaction()
{
try
{
this._transaction.Commit();
this._keepalive = false;
}
catch (Exception ex)
{
_hasError = true;
_ErrorMessage = ex.Message + "::" + ex.StackTrace;
}
}
public void RollbackTransaction()
{
try
{
this._transaction.Rollback();
this._keepalive = false;
}
catch (Exception ex)
{
_hasError = true;
_ErrorMessage = ex.Message + "::" + ex.StackTrace;
}
}
public string ExecuteSPNonQuerySingleReturnValue(string storedProcName, object[] parameterValues, string outParameterName, bool useTransaction = false)
{
_hasError = false; _ErrorMessage = "";
string result = "";
try
{
if (_oracleConnection.State == ConnectionState.Closed)
_oracleConnection.Open();
if (_oracleConnection.State == ConnectionState.Open)
{
OracleCommand objOraCommand = new OracleCommand();
objOraCommand.Connection = _oracleConnection;
objOraCommand.CommandText = storedProcName;
objOraCommand.CommandType = CommandType.StoredProcedure;
if (useTransaction == true)
objOraCommand.Transaction = this._transaction;
OracleCommandBuilder.DeriveParameters(objOraCommand);
for (int i = 0; i < parameterValues.Length; i++)
{
//objOraCommand.Parameters.Add(new OracleParameter(parameterNames[i], OracleType.VarChar)).Value = (parameterValues[i] == null) ? DBNull.Value : parameterValues[i];
// It threw exception over here. Below this line.
objOraCommand.Parameters[i].Value = (parameterValues[i] == null) ? DBNull.Value : parameterValues[i];
//objOraCommand.Parameters.AddWithValue(parameterNames[i], (parameterValues[i] == null) ? DBNull.Value : parameterValues[i]);
}
objOraCommand.ExecuteNonQuery();
result = objOraCommand.Parameters[outParameterName].Value.ToString();
}
}
catch (Exception ex)
{
_hasError = true;
_ErrorMessage = ex.Message;
}
finally
{
if (_oracleConnection.State == ConnectionState.Open && _keepalive == false)
_oracleConnection.Close();
}
return result;
}
この行では例外が発生しています。Count = 0のこのOracleParameterCollectionの無効な索引0
objOraCommand.Parameters[i].Value = (parameterValues[i] == null) ? DBNull.Value : parameterValues[i];
誰もが問題が何であるかを知っていますか?トランザクションなしで正常に動作していました。このメソッドは、トランザクションを追加した直後にエラーを出し始めました。
ビルドされた.Net oracleクライアントライブラリを使用しています。
using System.Data.OracleClient;
まだパラメータを追加していませんが、アクセスしようとしています。インデックス0が最初の要素です。空のパラメータ・コレクションにはパラメータはありません –
これは、プロシージャCHCCC_STSS(PSSS IN VARCHAR2、PCCC IN VARCHAR2、varReturnValue OUT VARCHAR2)をコールするプロシージャです。私はこれらのパラメータに適切な値を渡しています。 –
パラメータ、特にパラメータを使用する方法については、ADO.NETのチュートリアルを確認してください。 –