I'm using the following code to try to use Log Parser to fire off and dump the contents of a .csv file I have into a SQL database. I'm having to try to use a custom function to strip out non-alphanumeric characters so that the columns can be created dynamically, because the end goal is to have this work with any .csv file I give it.
Here's the code:
start-process -NoNewWindow -FilePath "C:\Program Files (x86)\Log Parser 2.2\LogParser.exe" -ArgumentList @"
"Create Function [dbo].[RemoveNonAlphaNumCharacters](@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin
Declare @KeepValues as varchar(50) = '%[^a-z0-9]%'
While PatIndex(@KeepValues, @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')
Return @Temp
End
SELECT.RemoveNonAlphaNumCharacters * INTO SQLCounters FROM C:\Users\SeanLon\Desktop\SQL_Log_0.csv" -i:CSV -o:SQL -server:MJNHNX4 -database:PerfmonCounters -driver:"SQL Server" -createTable:ON
"@
And the error:
start-process : Process with an Id of 221104 is not running.
At C:\Users\seanlon\Desktop\Performance\Powershell examples\LogParser.ps1:1 char:1
+ start-process -NoNewWindow -FilePath "C:\Program Files (x86)\Log Parser 2.2\LogP ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Start-Process], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.StartProcessCommand
Can start-process or log parser simply not handle that complex of SQL within the argument list? Or is the LogParser process closing out before something else happens?