【发布时间】:2015-03-19 20:06:50
【问题描述】:
有人可以帮我解决这个错误吗:
错误,0,作业失败。
2015 年 3 月 19 日 12:51:59,作业步骤在 PowerShell 脚本的第 75 行收到错误。对应的行是“$SqlAdapter2.Fill($DataSet2)”。更正脚本并重新安排作业。 PowerShell 返回的错误信息是:“使用“1”参数调用“填充”的异常:“'/' 附近的语法不正确。” '。处理退出代码-1。步骤失败。,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
【问题讨论】:
-
我们是否缺少其他代码?看起来您正在创建一个
$DataSet2对象,然后尝试将其用作$SqlAdapter2.Fill()方法的重载。对于这样的方法,您通常需要一些数据作为输入。我觉得很难帮助你,因为我不明白你想在这里做什么。 -
我很确定问题出在日期的格式上。我不是 SQL 专家,但我会建议像
$PreviousDate = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")这样的东西,看看是否能解决您的问题。我不认为 SQL 喜欢日期格式中的斜杠。
标签: powershell