I am trying to have powershell insert the contents of a file into a database table. the table is define as varchar(max)
the command, when run in SSMS, runs correctly. in powershell I am getting an error which I am assuming is due to the length of the contents (30,000 characters). the script runs fine on shorter texts. how can I get this to run?
$xml=get-content $file
$xml=([string]$xml).replace("'","''")
$cmd="INSERT INTO news.dbo.data_import(source_code,data,filename) VALUES (1,'$xml','$name' )"
invoke-sqlcmd $cmd
invoke-sqlcmd :
At C:\App_Vb\agencies\ap.ps1:9 char:4
+ invoke-sqlcmd $cmd
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Sqlcmd], ParserException
+ FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScriptCo
mmand