Execute sp_executeSql for select…into #table but Can’t Select out Temp Table Data

Using a global temporary table in this scenario could cause problems as the table would exist between sessions and may result in some problems using the calling code asynchronously. A local temporary table can be used if it defined before calling sp_executesql e.g. CREATE TABLE #tempTable(id int); execute sp_executesql N’INSERT INTO #tempTable SELECT myId FROM … Read more

Entity Framework 4.2 exec sp_executesql does not use indexes (parameter sniffing)

tl;dr update statistics We had a delete query with one parameter (the primary key) that took ~7 seconds to complete when called through EF and sp_executesql. Running the query manually, with the parameter embedded in the first argument to sp_executesql made the query run quickly (~0.2 seconds). Adding option (recompile) also worked. Of course, those … Read more