如果你编写的 SQL Server CE 应用程序出现下面的错误信息:
Error Code: 8007000E Message: Not enough storage is available to complete this operation. Minor Err.:0 Source: Microsoft SQL Server 2000 Windows CE Edition
或者
Error Code: 8007000E Message: 没有足够的存储空间来完成该操作。 Minor Err.:0 Source: Microsoft SQL Server 2000 Windows CE Edition
可能是以下原因导致的: 你在使用 SqlCeDataAdapter 对象填充 DataSet 后,没有显式地调用相关 SqlCeCommand 对象的 Dispose 方法。
解决方法: 在使用完 SqlCeDataAdapter 对象后,显式地调用与 SqlCeDataAdapter 对象相关的 SqlCeCommand 对象的 Dispose 方法。包括有 SelectCommand、InsertCommand、UpdateCommand 和 DeleteCommand。
示例代码:
public static DataSet LoadData() { string sqlstring = "";
// Make the connection to the SQL Server CE data source SqlCeConnection conn = new SqlCeConnection("Data Source=<completePath of SDF file>"); // Create the SqlCeDataAdapter object sqlCeDataAdapter da = new SqlCeDataAdapter(); // Create the DataSet object DataSet ds = new DataSet();
try { sqlstring = "select name from mytable where name = ?";
// Create the SelectCommand instance to run a select query da.SelectCommand = new SqlCeCommand();
// Set SelectCommand object properties da.SelectCommand.Connection = conn; da.SelectCommand.CommandText = sqlstring; da.SelectCommand.Parameters.Add(new SqlCeParameter("name", System.Data.SqlDbType.NVarChar, 30)); da.SelectCommand.Parameters["name"].Value = name;
// Populate the DataSet object da.Fill(ds,"name"); } catch (SqlCeException sqlx) { ShowErrors(sqlx); } catch (Exception x) { MessageBox.Show(x.Message.ToString()); } finally { // Explicitly dispose the SelectCommand instance da.SelectCommand.Dispose(); da.Dispose(); }
return ds; } 参考微软知识库: SqlCeCommand objects are not automatically disposed if you use a SqlCeDataAdapter object |