Dapper
Dapper copied to clipboard
Unable to reuse TempTable created when also sending params into the execute
If you add a param in the same call that creates the temp table then the temp table won't be accessible in future calls. This is a very strange behavior we came across today.
This works fine:
connection.Open();
await connection.ExecuteAsync(
@"create table #foo (val int not null);
insert #foo (val) values (123)");
await connection.ExecuteAsync(@"insert #foo (val) values (111)");
var vals = await connection.QueryAsync<int>(@"select * from #foo");
This fails. The error is that the temp table #foo doesn't exist.
connection.Open();
await connection.ExecuteAsync(
@"create table #foo (val int not null);
insert #foo (val) values (@InsertDate)", param: new { InsertDate = insertDate2 });
await connection.ExecuteAsync(@"insert #foo (val) values (111)");
var vals = await connection.QueryAsync<int>(@"select * from #foo");
Are you 100% the connection was open in the failing case? Not at a PC to try running it (will try to find time this weekend), but : that's the usual explanation for this happening.
Yes 100%