.NET SQL CE核心 - 没有足够的存储空间来完成此操作

时间:2011-06-19 07:17:01

标签: .net sql

我正在使用SQL CE在我的应用程序中存储数据。执行大约3000次后,我在下面的代码中出错:

  

“没有足够的存储空间来完成此操作”

错误发生在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 ID=@id"; 
    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 个答案:

答案 0 :(得分:0)

声明参数时使用此: deleteCmd.Parameters.Add(“@ id”,SqlDbType.Int,“ID”);