gpt4 book ai didi

powershell - powershell:使用 “Fill”参数调用 “1”的异常: “Incorrect syntax near '/'.”'

转载 作者:行者123 更新时间:2023-12-03 00:17:55 26 4
gpt4 key购买 nike

有人可以帮助我解决此错误:

Error,0,The job failed.
03/19/2015 12:51:59,A job step received an error at line 75 in a PowerShell script. The corresponding line is ' $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 '/'." '. Process Exit Code -1. The step failed.,00:00:02,0,0,,,,0



我的代码是:
#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

最佳答案

您尚未打开连接。这就是问题。

在此行之后:

$connection2.ConnectionString = $connectionString2

添加此行:
$connection2.Open()

关于powershell - powershell:使用 “Fill”参数调用 “1”的异常: “Incorrect syntax near '/'.”',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29153974/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com