Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

SQL Stored Procedure to text file

$
0
0

I have a code snippet below that is suppose to execute a stored procedure into a text file. The error i am recieving is "Syntax error in From clause". When i transfer the SQL script to SSMS it runs fine. Is there another erorr i am not seeing? Thank you for the help

 

$SqlConnection = New-Object System.Data.OleDb.OleDbConnection
$SqlConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ServerPath + ";Extended Properties=""Text;HDR=YES;"""
$SqlCmd = New-Object System.Data.OleDb.OleDbCommand("SELECT * INTO [Test#txt] FROM OPENROWSET('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;','set fmtonly off; set nocount on; exec DBName.Schema.StoredProcedure);",$SqlConnection)
$SqlConnection.Open()
$SqlCmd.ExecuteNonQuery()
$SqlConnection.Close()

Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>