Does SQL CE ExecuteResultSet need to be cleaned up?

*爱你&永不变心* 提交于 2019-12-24 07:25:45

问题


I have a table with about 150 rows in it. These are the data types in the table:

  • int (PK)
  • nvarchar(52)
  • tinyint
  • datetime
  • uniqueidentifier
  • nvarchar(300)
  • bit
  • bit
  • bit
  • bit

I download the data from a web service and insert into the database. When I do that it works fine.

I later in the execution of my program I call the web service again. Since I may have updated some of the data I downloaded the first time, I check the db to see the row has changed. If it has then I leave it, if not then I update it. I think it is the check to see if it is there that is causing me the problems. When I do it I get this error:

"SQL Server Compact has exceeded the buffer size. The default size can be increased on initialization by modifying the ssce: max buffer size property. [ The default size = 655360 ]"

NOTE: This does not happen right away on the second time around. (Meaning that I stepped through some rows and they updated just fine.)

The only thing I can think of is that my result set is not getting cleared out. (Though I have used the same code to access the database with no problems.)

Here is my code:

public static SqlCeResultSet SetupTable(string tableName, string indexName, 
   bool allowUpdates, params object[] whereValues)
{
    // The command used to affect the data
    var command = new SqlCeCommand
                      {

                          CommandType = CommandType.TableDirect,
                          Connection = _connection,
                          // Set the table that we are going to be working with.
                          CommandText = tableName,
                          // Indicate what index we are going to be using.  
                          IndexName = indexName
                      };

    if ((whereValues != null) && (whereValues.Length > 0))
        command.SetRange(DbRangeOptions.Match, whereValues, null);

    // Get the table ready to work with.
    if (allowUpdates)
        return command.ExecuteResultSet(
                        ResultSetOptions.Updatable | ResultSetOptions.Scrollable);
    else
        return command.ExecuteResultSet(ResultSetOptions.Scrollable);
}

The call looks something like this:

SetupTable("tblMyTable", "IndexName", true, whereValue);

The weird thing is that it all works fine if I don't use the SetRange. It seems to me that it should use less buffer space if I use a SetRange (not more as it seems to be doing).

After it crashes with this error calls in Query Analyzer will also give the same message. I could up my buffer size but I am sure it will just take a bit longer to fill up (especally because I am passing in a "where" value that sets the range to a single row).

One thing to note is that I call the above code for each row in my table. (That is why I am asking if I should be cleaning up my results.) While I do call it for each row in my table, the previous one goes out of scope before I make a new one.

Any help would be great!

(Note: if you want to see the full code for the SetupTable stuff I put the whole class here.)


回答1:


Are you disposing your command somewhere?

Anything that implements IDisposable (has a Dispose() method) should be disposed. That's the general rule. Since you're calling this method for every row, you should dispose your command.



来源:https://stackoverflow.com/questions/5084659/does-sql-ce-executeresultset-need-to-be-cleaned-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!