Skip to content

Import-DbaCsv close SQL connection #10062

@Maxiz80

Description

@Maxiz80

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

I've noticed that when Import-DbaCsv is executed, sql connection get closed.
Is it an expected behavior?

Also when I need to import in a specific database I need to specify in sql connection, it seems that "-Database" parameter get ignored

Steps to Reproduce

$Sqlconnection = Connect-DbaInstance -SqlConnectionOnly -SqlInstance $DefaultSqlServer -TrustServerCertificate -NonPooledConnection -StatementTimeout 0 -EncryptConnection -AppendConnectionString "Integrated Security=True;Multiple Active Result Sets=False"

$Sqlconnection .Open()

Import-DbaCsv -SqlInstance $Sqlconnection -Database $DBName -Table $Table -Schema "dbo" -Path $DataTable -NoProgress -AutoCreateTable

$Sqlconnection .State
(Closed)

Please confirm that you are running the most recent version of dbatools

2025.12.4

Other details or mentions

No response

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe), Windows PowerShell ISE (powershell_ise.exe)

PowerShell Host Version

5.1

SQL Server Edition and Build number

2022
16.0.4222.2

.NET Framework Version

4.8.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions