简体   繁体   English

powershell:使用“1”参数调用“填充”的异常:“'/'附近的语法不正确。” '

[英]powershell: Exception calling “Fill” with “1” argument(s): “Incorrect syntax near '/'.” '

Can someone please help me with this error:有人可以帮我解决这个错误吗:

Error,0,The job failed.错误,0,作业失败。
03/19/2015 12:51:59,A job step received an error at line 75 in a PowerShell script. 03/19/2015 12:51:59,一个作业步骤在 PowerShell 脚本的第 75 行收到错误。 The corresponding line is ' $SqlAdapter2.Fill($DataSet2)'.对应的行是“$SqlAdapter2.Fill($DataSet2)”。 Correct the script and reschedule the job.更正脚本并重新安排作业。 The error information returned by PowerShell is: 'Exception calling "Fill" with "1" argument(s): "Incorrect syntax near '/'." PowerShell 返回的错误信息是:“用“1”个参数调用“填充”的异常:“'/'附近的语法不正确。” '. '。 Process Exit Code -1.进程退出代码 -1。 The step failed.,00:00:02,0,0,,,,0步骤失败。,00:00:02,0,0,,,,0

My code is:我的代码是:

#Exceute the procedure and place the .csv file on server

    $CurrentDate = Get-Date
    $CurrentDate = $CurrentDate.ToShortDateString()
    $PreviousDate = (Get-Date).AddDays(-1).ToShortDateString()

       $server2 = "XXXXXXX"
        $database2 = "XXXXXX"
        $query2 = "exec XXX.XXXXX_XXXXX_daily_report"+$PreviousDate+","+$PreviousDate 



     $extractFile2 = "C:\XXX\XXX\XXX\XXX\XXX_daily_Report"+($CurrentDate)+".csv"

        $connectionTemplate2 = "Data Source={0};Integrated Security=SSPI;Initial Catalog={1};"
        $connectionString2 = [string]::Format($connectionTemplate2, $server2, $database2)
        $connection2 = New-Object System.Data.SqlClient.SqlConnection
        $connection2.ConnectionString = $connectionString2

        $command2 = New-Object System.Data.SqlClient.SqlCommand
        $command2.CommandText = $query2
        $command2.Connection = $connection2
        $command2.CommandTimeout=0 

        $SqlAdapter2 = New-Object System.Data.SqlClient.SqlDataAdapter
        $SqlAdapter2.SelectCommand = $command2
        $DataSet2 = New-Object System.Data.DataSet
        $SqlAdapter2.Fill($DataSet2)
        $connection2.Close()

        # dump the data to a csv
        $DataSet2.Tables[0] | Export-Csv -NoTypeInformation $extractFile2

You haven't opened the connection yet.您尚未打开连接。 That is the issue.这就是问题所在。

Right after this line:在这一行之后:

$connection2.ConnectionString = $connectionString2

Add this line:添加这一行:

$connection2.Open()

In the exec statement, you might need to put a space between these two pieces: _daily_report"+$PreviousDate在 exec 语句中,您可能需要在这两部分之间放置一个空格:_daily_report"+$PreviousDate

Also, you can just do this -- write the whole SQL command as one string:此外,您可以这样做——将整个 SQL 命令写为一个字符串:

$query2 = "exec XXX.XXXXX_XXXXX_daily_report $PreviousDate, $PreviousDate" $query2 = "exec XXX.XXXXX_XXXXX_daily_report $PreviousDate, $PreviousDate"

because Powershell will insert the values of those variables into the string for you.因为 Powershell 会为您将这些变量的值插入到字符串中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“ 0”参数调用“ ExecuteReader”的异常:“'='附近的语法不正确。” - Exception calling “ExecuteReader” with “0” argument(s): “Incorrect syntax near '='.” 使用ExecuteNonQuery()的Powershell脚本抛出异常“'s'附近的语法不正确。” - Powershell Script using ExecuteNonQuery() throws exception “Incorrect syntax near 's'.” MySQL查询异常在Powershell v4中使用“ 2”参数调用“填充” - MySQL Query Exception calling “Fill” with “2” argument(s) from Powershell v4 Powershell:使用“ 3”参数调用“ AttachDatabase”的异常 - Powershell: Exception calling “AttachDatabase” with “3” argument(s) PowerShell:使用“7”参数调用“GetListItems”异常 - PowerShell: Exception calling “GetListItems” with “7” argument(s) 使用“1”参数调用“SetAccessRule”的异常::: Powershell 错误 - Exception calling "SetAccessRule" with "1" argument(s) ::: Powershell Error Power Shell Invoke-SQLSelect:使用“1”参数调用“Fill”的异常: - Power Shell Invoke-SQLSelect : Exception calling "Fill" with "1" argument(s): Powershell Invoke-SSHCommand:使用“1”参数调用“EndExecute”的异常 - Powershell Invoke-SSHCommand: Exception calling “EndExecute” with “1” argument(s) PowerShell 异常从另一个函数中使用“0”参数调用“Start” - PowerShell Exception calling “Start” with “0” argument(s) from within another function Powershell 将文件上传到 SharePoint:异常调用带有“0”参数的“ExecuteQuery”错误 - Powershell uploading files to SharePoint : Exception calling “ExecuteQuery” with “0” argument(s) error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM