开发者

.NET SQL CE Core - Not enough storage is available to complete this operation

开发者 https://www.devze.com 2023-03-14 02:53 出处:网络
I am using SQL CE to store data in my application. I got an error with the below code after executing it for around 3000 times:

I am using SQL CE to store data in my application. I got an error with the below code after executing it for around 3000 times:

"Not enough storage is available to complete this operation"

The error is happened on a LIVE application.

SqlCeConnection开发者_JAVA百科 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();
}


when declaring the parameter use this: deleteCmd.Parameters.Add("@id", SqlDbType.Int, "ID");

0

精彩评论

暂无评论...
验证码 换一张
取 消