Can someone please explain what this means (from the Dapper.net website)
Limitations and caveats
Dapper caches information about every query it runs, this allow it to materialize objects quickly and process parameters quickly. The current implementation caches this information in a ConcurrentDictionary object. The objects it stores are never flushed. If you are generating SQL strings on the fly without using parameters it is possible you will hit memory issues. We may convert the dictionaries to an LRU Cache.
I am not able to understand what the line in bold means. I am using SQL Server and c# client.
Can someone please give a sample of c# code that will create this memory issue. thank you
To clear SQL Server's cache, run DBCC DROPCLEANBUFFERS , which clears all data from the cache. Then run DBCC FREEPROCCACHE , which clears the stored procedure cache.
FlushCache is the SQL Server routine that performs the checkpoint operation. The following message is output to the SQL Server error log when trace flag ( 3504 ) is enabled. 2012-05-30 02:01:56.31 spid14s FlushCache: cleaned up 216539 bufs with 154471 writes in 69071 ms (avoided 11796 new dirty bufs) for db 6:0.
Use DBCC DROPCLEANBUFFERS to test queries with a cold buffer cache without shutting down and restarting the server. To drop clean buffers from the buffer pool and columnstore objects from the columnstore object pool, first use CHECKPOINT to produce a cold buffer cache.
Overview of DBCC FREEPROCCACHE command. We can use the DBCC FREEPROCCACHE command to clear the procedural cache in SQL Server. We might drop a single execution plan or all plans from the buffer cache. SQL Server needs to create new execution plans once the user reruns the query.
If you are generating SQL strings on the fly without using parameters it is possible you will hit memory issues.
You can do this:
cmd.CommandText = "SELECT email, passwd, login_id, full_name " +
"FROM members " +
"WHERE email = '" + email + "'";
or you can do this:
string s = "SELECT email, passwd, login_id, full_name " +
"FROM members WHERE " +
"email = @email";
SqlCommand cmd = new SqlCommand(s);
cmd.Parameters.Add("@email", email);
The latter is parameterized. It will be cached once. The former is not parameterized. It will be cached every time you write a query like it with a different value for email
. This will explode your memory.
The latter is vastly superior. It avoids injection attacks. dapper can cache it once. SQL Server will compile the execution plan once and cache it.
You should (imperative) already be using parameterized queries. If you aren't, drop everything you are doing and make this an immediate priority.
Can someone please give a sample of c# code that will create this memory issue. thank you
Just do the former in a loop. Watch your memory grow. Do the latter in a loop. Watch your memory not grow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With