Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

Unable to reuse TempTable created when also sending params into the execute

Open bdlee420 opened this issue 1 year ago • 2 comments

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");

bdlee420 avatar Mar 29 '24 22:03 bdlee420

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.

mgravell avatar Mar 29 '24 23:03 mgravell

Yes 100%

bdlee420 avatar Mar 30 '24 15:03 bdlee420