【发布时间】:2017-01-26 15:05:20
【问题描述】:
我正在尝试运行多个 SQL 查询并在一些 txt/csv 文件中获取结果,但我收到了一个我无法修复的错误。有什么建议吗?
$dbServer = "dbserver"
$extractFile = "C:\test\" + $timer + ".csv"
$Database = "b
$User = "Admin"
$Pass = "psswd"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$dbServer;Database=$db;uid=$User;password=$Pass;"
$SQLConnection.Open()
$SQLCommand = $SQLConnection.CreateCommand()
$SQLCommand.CommandText =
"select count(*) 'Nombre de Address mail' FROM dbo.UsersParticipations"
"select count(*) 'Nombre de Transactions' FROM dbo.Transactions;"
$readAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$readSet = New-Object System.Data.DataSet
$readAdapter.SelectCommand = $SQLCommand
$readAdapter.Fill($readSet) |out-null
$SQLConnection.Close()
Foreach ($row in $readSet.Tables[0].rows) {
Write-Output "Adress"
Write-Output "$($row.size) $($row.job)"
}
Foreach ($row in $readSet.Tables[1].rows) {
Write-Output "Transactions"
Write-Output "$($row.free) "
}
这是我得到的错误:
Exception calling "Fill" with "1" argument(s): "Invalid object name 'dbo.UsersParticipations'."
At C:\Efiester\test2.ps1:18 char:1
+ $readAdapter.Fill($readSet) |out-null
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SqlException
【问题讨论】:
-
错误是什么?
-
使用“1”参数调用“Fill”的异常:“无效的对象名称'dbo.UsersParticipations'。”在 C:\Efiester\test2.ps1:18 char:1 + $readAdapter.Fill($readSet) |out-null + ~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SqlException
-
从评论中添加了错误信息
标签: sql powershell output