2011-06-19 52 views
2

我正在使用SQL CE將數據存儲在我的應用程序中。我得到了與下面的代碼錯誤執行它周邊的3000次後:.NET SQL CE核心 - 沒有足夠的存儲空間來完成此操作

「沒有足夠的存儲是可用於完成此操作」

的錯誤是發生在一個LIVE應用。

SqlCeConnection connection; 
SqlCeTransaction transaction; 

try 
{ 
    connection = new SqlCeConnection(connectionString); 
    connection.Open(); 
    transaction = connection.BeginTransaction(); 
    SqlCeCommand deleteCmd = connection.CreateCommand(); 
    deleteCmd.CommandText ="Delete from EJData where [email protected]"; 
    deleteCmd.Parameters.Add("@id", SqlDbType.Int, Int32.MaxValue.ToString().Length, "ID"); 
    adapter.DeleteCommand = deleteCmd; 
    adapter.DeleteCommand.Transaction = transaction; 
    DataRow[] r = dataSet.Tables[0].Select("ID >=" + firstRecordID + " and ID<=" + lastRecordID); 
    foreach (DataRow row in r) 
    { 
     row.Delete(); 
    } 

    adapter.Update(dataSet,"EJData"); 
    transaction.Commit(CommitMode.Immediate); 
    transaction.Dispose(); 
    transaction = null; 
} 

catch (...) 

{ 
    ... 
} 

finally 

{ 
    if (adapter.DeleteCommand != null) 
    { 
     adapter.DeleteCommand.Dispose(); 
    } 

    connection.Close(); 
} 
+1

3000次 - 3000次調用這個方法嗎?或者循環中有3000個項目的一個呼叫?我不知道這筆交易是否太大,而且一些較小的交易可能會更成功。 –

+0

即使由於不推薦,請嘗試添加GC.Collect();在connection.Close(); – Dementic

回答

0

聲明參數使用時: deleteCmd.Parameters.Add( 「@ ID」,SqlDbType.Int, 「ID」);

相關問題