我在TFS存储库中维护我的Powershell脚本文件和SQL文件。我正在尝试从Powershell脚本(它也位于TFS中)准备我的SQL文件。我在构建中调用这个powershell脚本。我在执行时遇到错误。在位于TFS的Powershell脚本文件中,如何读取驻留在TFS中的SQL文件?
$ServerInstance = "ABCServer"
$Database = "MyDB"
$ConnectionTimeout = 30
$Query = get-content "$/MYPROJECT/Queries/GetProjects.sql"
$QueryTimeout = 120
$conn=new-object System.Data.SqlClient.SQLConnection
$ConnectionString = "Server={0};Database={1};Integrated Security=True;Connect Timeout={2}" -f $ServerInstance,$Database,$ConnectionTimeout
$conn.ConnectionString=$ConnectionString
$conn.Open()
$cmd=new-object system.Data.SqlClient.SqlCommand($Query,$conn)
$cmd.CommandTimeout=$QueryTimeout
$ds=New-Object system.Data.DataSet
$da=New-Object system.Data.SqlClient.SqlDataAdapter($cmd)
[void]$da.fill($ds)
$ds.Tables[0] | foreach {
write-host 'Name value is : ' + $_.Title
}
$conn.Close()
#$ds.Tables
我PowerShell是保存在 “$/MYPROJECT/PowershellScripts/QueryDB.ps1”
我有这个PowerShell的加入TFS任务在我的构建步骤。我收到以下错误
**PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
Exception calling "Open" with "0" argument(s): "Cannot open database "MyDB" requested by the login**
貌似TFS一部分被不同的帐户下运行,并缺乏权限的数据库。检查Sql Server的日志失败的登录尝试。 – vonPryz