I m using VS2008 with oledb provider. Here is the sample code:
Int32 Counter, LenderCount;
string ReturnVal = "";
string[] Lenders;
char[] arrParam = new char[] { ',' };
string Result = SaveLenBegin(); //One procedure is executed here
if (Result.Trim() != "-1")
{
OleDbConnection con = this.MyConnection();
OleDbCommand cmd = con.CreateCommand();
OleDbParameter[] LenderExtrapolate = new OleDbParameter[4];
cmd.CommandType =
CommandType.StoredProcedure;
cmd.CommandTimeout =
Convert.ToInt32(HttpContext.Current.Application["DB.CommandTimeOut"], CultureInfo.InvariantCulture);
cmd.CommandText =
"procNameHere";
Lenders = LenderList.Split(arrParam);
for (LenderCount = 0; LenderCount < Lenders.Length; LenderCount++)
{
LenderExtrapolate[0] =
new OleDbParameter("@mp_id", Lenders[LenderCount]);
LenderExtrapolate[0].Size = 5;
LenderExtrapolate[0].OleDbType =
OleDbType.Integer;
LenderExtrapolate[0].Direction =
ParameterDirection.Input;
LenderExtrapolate[1] =
new OleDbParameter("@created_by", userID.Trim());
LenderExtrapolate[1].OleDbType =
OleDbType.VarChar;
LenderExtrapolate[1].Size = 20;
LenderExtrapolate[1].Direction =
ParameterDirection.Input;
LenderExtrapolate[2] =
new OleDbParameter("@result", 0);
LenderExtrapolate[2].Size = 5;
LenderExtrapolate[2].OleDbType =
OleDbType.Integer;
LenderExtrapolate[2].Direction =
ParameterDirection.Output;
LenderExtrapolate[3] =
new OleDbParameter("@message", "");
LenderExtrapolate[3].OleDbType =
OleDbType.VarChar;
LenderExtrapolate[3].Size = 35;
LenderExtrapolate[3].Direction =
ParameterDirection.Output;
for (Counter = 0; Counter < LenderExtrapolate.Length; Counter++)
{
cmd.Parameters.Add(LenderExtrapolate[Counter]);
}
cmd.ExecuteNonQuery(); //Error is @ this line
ReturnVal =
Convert.ToString(cmd.Parameters[2].Value, CultureInfo.InvariantCulture);
cmd.Parameters.Clear();
}
}
return ReturnVal;
}
Error is: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
For loop is executed fine at first time. Error occures from second round.
Plese help. it is very urgent