I switched over to a regular sql statement to create a temporary table, and then tried to query it. What I realized was the new sql.Request was most of my problem. The temporary table doesn't exist on another connection/request/thread.
So this was my solution:
var table = new sql.Table('#atable');
table.create = true;
table.columns.add('a', sql.Int, { nullable: false});
table.rows.add(1);
table.rows.add(2);
table.rows.add(3);
var request = new sql.Request();
request.bulk(table, function(err, rowCount){
if(err){
console.log('bulk insert error');
console.log(err);
return;
}
request.query('select * from #atable', function(err, recordset){
if(err){
console.log('taco error:' + err);
return;
}
console.log('taco recordset:');
console.log(recordset);
});
});
It's a subtle change. Inside the request.bulk call I used the same request object (smartly named request) to query the table. I wasn't creating a new connection object so I didn't realize I was using a connection where the table didn't exist.