PDA

View Full Version : مشكل there is already an open datareader associated with this command which must be closed first



aminpourazadeh
سه شنبه 20 دی 1390, 13:07 عصر
سلام من اين تابع رو نوشتم ولي موقع اجرا خطا مي ده
و نمي تونه ترا كنش را كاميت كنه






public int Save(clsGlobal.FormState _FormState, PrdProductionBatchStr _PrdProductionBatchStr, ref clsGlobal.Error _Error, DataTable dtbItem, string LogDes)
{

if (_DcDarmanGazDataContext.Connection.State == ConnectionState.Closed)
_DcDarmanGazDataContext.Connection.Open();
DbTransaction tr = _DcDarmanGazDataContext.Connection.BeginTransactio n();
_DcDarmanGazDataContext.Transaction = tr;
int intRes = -1;

// using (var tr = new TransactionScope())
// {
//var trxOptions = new TransactionOptions();
//trxOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
//using (var transaction = new TransactionScope(TransactionScopeOption.Required, trxOptions))

//{
try
{
if (_FormState == clsGlobal.FormState.Add || _FormState == clsGlobal.FormState.Copy)
{
intRes = Convert.ToInt32(((Sp_PrdProductionBatch_INSERTResu lt)_DcDarmanGazDataContext.Sp_PrdProductionBatch_I NSERT(_PrdProductionBatchStr.DocNo, _PrdProductionBatchStr.DocDate, _PrdProductionBatchStr.fk_tblPrdProductLineID, _PrdProductionBatchStr.ProductDate, _PrdProductionBatchStr.ChargeDate, _PrdProductionBatchStr.ChargerName, _PrdProductionBatchStr.Des).Single()).Column1.Valu e);
}
else if (_FormState == clsGlobal.FormState.Edit)
{
if (_DcDarmanGazDataContext.Sp_PrdProductionBatch_UPD ATE(_PrdProductionBatchStr.DocNo, _PrdProductionBatchStr.DocDate, _PrdProductionBatchStr.fk_tblPrdProductLineID, _PrdProductionBatchStr.ProductDate, _PrdProductionBatchStr.ChargeDate, _PrdProductionBatchStr.ChargerName, _PrdProductionBatchStr.Des, _PrdProductionBatchStr.Id) >= 0)
intRes = _PrdProductionBatchStr.Id;
}
}
catch (SqlException ex)
{
if (ex.Number == (int)clsGlobal.Error.Index)
_Error = clsGlobal.Error.Index;
else if (ex.Number == (int)clsGlobal.Error.Index1)
_Error = clsGlobal.Error.Index1;
else
_Error = clsGlobal.Error.Ambiguous;
_DcDarmanGazDataContext.Transaction.Rollback();
return -1;
}

try
{

int? intfk_tblPrdCylanderID, intNetWeight;
DateTime? dtFetchDate = null, dtCylanderTestDate;
DataView dv = new DataView(dtbItem);
try
{

dv.RowFilter = "I=1 AND D=0";
for (int j = 0; j < dv.Count; j++)
{
try
{
if (dv[j]["fk_tblPrdCylanderID"].ToString() != "")
intfk_tblPrdCylanderID = Convert.ToInt32(dv[j]["fk_tblPrdCylanderID"]);
else
intfk_tblPrdCylanderID = null;
if (dv[j]["NetWeight"].ToString() != "")
intNetWeight = Convert.ToInt32(dv[j]["NetWeight"]);
else
intNetWeight = null;

if (dv[j]["CylanderTestDate"].ToString() != "")
dtCylanderTestDate = Convert.ToDateTime(dv[j]["CylanderTestDate"]);
else
dtCylanderTestDate = null;
_DcDarmanGazDataContext.Sp_PrdProductionBatchItems _INSERT(intRes, intfk_tblPrdCylanderID, Convert.ToInt16(dv[j]["Row"]), dv[j]["CylanderType"].ToString(), intNetWeight, dtFetchDate, dtCylanderTestDate, dv[j]["GreenTagSerial"].ToString(), dv[j]["SpecialNo"].ToString());
}
catch
{
_DcDarmanGazDataContext.Transaction.Rollback();
_Error = clsGlobal.Error.Ambiguous;
return -1;
}
}
}
catch { }
try
{

dv.RowFilter = "I=0 AND D=0 AND U=1";
for (int j = 0; j < dv.Count; j++)
{
try
{
if (dv[j]["fk_tblPrdCylanderID"].ToString() != "")
intfk_tblPrdCylanderID = Convert.ToInt32(dv[j]["fk_tblPrdCylanderID"]);
else
intfk_tblPrdCylanderID = null;
if (dv[j]["NetWeight"].ToString() != "")
intNetWeight = Convert.ToInt32(dv[j]["NetWeight"]);
else
intNetWeight = null;

if (dv[j]["CylanderTestDate"].ToString() != "")
dtCylanderTestDate = Convert.ToDateTime(dv[j]["CylanderTestDate"]);
else
dtCylanderTestDate = null;
_DcDarmanGazDataContext.Sp_PrdProductionBatchItems _UPDATE(intRes, intfk_tblPrdCylanderID, Convert.ToInt16(dv[j]["Row"]), dv[j]["CylanderType"].ToString(), intNetWeight, dtFetchDate, dtCylanderTestDate, dv[j]["GreenTagSerial"].ToString(), dv[j]["SpecialNo"].ToString(), Convert.ToInt32(dv[j]["ID"]));
}
catch
{
_DcDarmanGazDataContext.Transaction.Rollback();
_Error = clsGlobal.Error.Ambiguous;
return -1;
}
}
}
catch { }
try
{
dv.RowFilter = "I=0 AND D=1";
for (int j = 0; j < dv.Count; j++)
{
try
{
_DcDarmanGazDataContext.Sp_PrdProductionBatchItems _DELETE(Convert.ToInt32(dv[j]["ID"]));
}
catch
{
_DcDarmanGazDataContext.Transaction.Rollback();
_Error = clsGlobal.Error.Ambiguous;
return -1;
}
}
}
catch
{ }

}
catch (SqlException ex)
{
_DcDarmanGazDataContext.Transaction.Rollback();
_Error = clsGlobal.Error.Ambiguous;
return -1;
}
try
{
if (intRes >= 0)
_ctrlManLog.Insert("tblPrdProductionBatch", "سیلندر", (short)clsGlobal.Opration.Save, LogDes);
}
catch
{
_DcDarmanGazDataContext.Transaction.Rollback();
_Error = clsGlobal.Error.Ambiguous;
return -1;
}
_DcDarmanGazDataContext.Transaction.Commit();
if (_DcDarmanGazDataContext.Connection.State == ConnectionState.Open)
_DcDarmanGazDataContext.Connection.Close();

// transaction.Complete();
return intRes;
// }
//}

}

zarrinnegar
سه شنبه 20 دی 1390, 13:23 عصر
ار عنوان تاپیک معلومه که datareder داره قبل از اینکه close بشه دوباره open میشه
باید ببینی توی کدوم خط اخطار میده بعدش قبل از اون رو چک کنی ببینی کجا open شده ولی close نشده و دوباره داری Open میکنی

aminpourazadeh
سه شنبه 20 دی 1390, 13:58 عصر
ار عنوان تاپیک معلومه که datareder داره قبل از اینکه close بشه دوباره open میشه
باید ببینی توی کدوم خط اخطار میده بعدش قبل از اون رو چک کنی ببینی کجا open شده ولی close نشده و دوباره داری Open میکنی


به اين خط _DcDarmanGazDataContext.Transaction.Commit(); داره خطا مي ده

من توي پرو‍ه ام اصلا datareder ننوشتم

1 بار ثبت مي كنه و لي براي بار دوم به اينجا گير مي ده

اين پروژه با لينك

نمي دونم مشكل كجاست !!!