Write-DbaDbTableData can't create useful temp tables (anymore)
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
Temp tables created by Write-DbaDbTableData are automatically deleted immediately after being populated, because it closes the connection before exiting. Temp tables did persist prior to commit f5f0062680d66ac70a33ca8a35e31ea5199784fd.
WARNING: [11:24:57][Invoke-DbaQuery] [xxx] Failed during execution | Invalid object name '#foo'.
Steps to Reproduce
$conn = Connect-DbaInstance -SqlInstance xxx
$data = ConvertFrom-Csv "a,b`n1,2"
Write-DbaDbTableData -SqlInstance $conn -Table '#foo' -AutoCreateTable -InputObject $data
Invoke-DbaQuery -SqlInstance $conn -Query 'select * from #foo'
$data = ConvertFrom-Csv "a,b`n1,2"
Write-DbaDataTable -SqlInstance xxx -Table '##foo' -AutoCreateTable -InputObject $data
Invoke-DbaQuery -SqlInstance xxx -Query 'select * from ##foo'
Expected output for both commands:
a b
- -
1 2
Please confirm that you are running the most recent version of dbatools
1.1.145
Other details or mentions
The use case, which worked in older versions of dbatools is:
- Load data into a temp table
- Call a stored procedure to manipulate & move the data to a real table
Workaround is to create a real table in tempdb and then drop with when work is complete, but this sparks less joy.
What PowerShell host was used when producing this error
Windows PowerShell (powershell.exe)
PowerShell Host Version
Name Value
---- -----
PSVersion 5.1.20348.859
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.859
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
SQL Server Edition and Build number
Microsoft SQL Server 2017 (RTM-CU29) (KB5010786) - 14.0.3436.1 (X64) Mar 18 2022 13:21:03 Copyright (C) 2017 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2012 R2 Datacenter 6.3
.NET Framework Version
PSChildName Version
----------- -------
Client 4.8.04161
Full 4.8.04161
Client 4.0.0.0
I don't see this as a high priority and needs to have a larger discussion on how we manage and control the connection/session to an instance between commands. There are other commands that because of how we manage the connection may be causing inadvertent issues, #8765 as an example.
I totally agree. As soon as version 2.0 is released I will have a look at connection management again and will make sure that this issue is solved. But I would like to have a look at a bigger scope. And I prefer to change connection handling independend from a big release with many other changes. So that is why I would like to wait until 2.0 is released.
Changing connection management will be major release, based on implementation maybe a minor release. Most users are scripting around how connections are managed now so changes to that expected behavior has to warrant a large bump in version.
@bstrautin we are not discounting your issue to be clear but the change made that broke the functionality was made 2 years ago and you are first one to bring it up.
If more users want to up vote using 👍 will help show the priority.