0

Reference: [https://dbatools.io/functions/import-dbacsvtosql/]

Trying to impact a few information into SQL Server using DBA Tools, and I get the error when I attempt to import - The rest of the script works fine, except for the Import-csv:

Import-DbaCsvToSql : The '++' operator works only on numbers. The operand is a 'System.IO.FileInfo'. At line:5 char:5

Query I am using to export and import is:

$query2 = "select * from "+" $($_.Table1ToKeep)"
$ExportFile = "\\Server\e$\DatabaseNameTable2Keep\"+"$($_.Table1ToKeep)_$($_.TrgServer)"+".csv"

Invoke-Sqlcmd2 -serverinstance $_.TrgServer -database $_.DataBaseName -Query $query2 | Export-CSV -Path $ExportFile -Delimiter "|" -NoTypeInformation 

$fileList = Get-ChildItem \\ServerName\e$\DatabaseNameTable2Keep\ -Filter *.csv
foreach ($i in $fileList){
    (Get-Content -Path $i.FullName ) -replace '"' , '' | Set-Content -Path $i.FullName
}

Import-DbaCsvToSql -Csv "\\ServerName\e$\DatabaseNameTable2Keep\$($_.Table1ToKeep)_$($_.TrgServer).csv" -SqlInstance Instance01 -Database DatabaseName -Table "$($_.Table1ToKeep)_$($_.TrgServer)"  -Delimiter "`|" -FirstRowColumns 

Thanks

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Gabi
  • 21
  • 1
  • 6
  • Which line is line 29, as per the error message? – boxdog Sep 03 '18 at 14:34
  • The line 29 is the **Import-DbaCsvToSql** - All the other parts work fine. – Gabi Sep 03 '18 at 14:37
  • 1
    Could you add definition of Import-DbaCsvToSql function? – Kirill Pashkov Sep 03 '18 at 14:46
  • Sure - It's from DBA Tools: [https://dbatools.io/functions/import-dbacsvtosql/] – Gabi Sep 03 '18 at 14:51
  • that link gives `Sorry, we're in the middle of an upgrade and this link is too new or too old ;) ` – Daniel Agans Sep 03 '18 at 17:44
  • https://dbatools.io/functions/import-dbacsvtosql/ – Gabi Sep 04 '18 at 09:09
  • I am having the same problem out of the blue. I have been using the Import-DbaCsvToSql function for weeks and then out of no where I started experiencing this error. Have you found a resolution? – jrob24 Sep 20 '18 at 21:02
  • Hello, I have not found the solution for this. Hence, I changed my script where I export the table I want as a [DataTable] and then, I [Write-DbaDataTable] this exported table. Also using DBA Tools scripts. – Gabi Sep 24 '18 at 09:05

0 Answers0