This project is read-only.

Execute *.sql script via SQLPSX

Mar 16, 2010 at 2:53 PM


maybe i didn't looked deep enough,

 but is there a way instead of using a query in the Set-Sqldata command to pass a *.sql  file?

I'd like to run some create Procedure - scripts via SQLPSX.


Mar 16, 2010 at 10:48 PM

Not directly, but you could work around the issue by assigning the contents of your sql file to a variable as follows:

$file = $(resolve-path test.sql).path
$out =  [System.IO.File]::ReadAllText("$file")
get-sqldata -sqlserver "Z002\sql2k8" -dbname pubs -qry $out
Mar 17, 2010 at 5:30 PM

Thank you that worked for me.
Maybe a command for this would be an enhancement for next Versions ;-)

May 16, 2010 at 4:24 PM
I think it might be possible to split a script at the go lines and to send the single blocks to invoke-query. Adding handlers for print output and error messages to invoke-query might give some interessting features. But I admit, that for practical jobs I would just invoke sqlcmd. It would require a lot of work, to get real benefits from the above outlined solution compared with using the well tested tools.