【发布时间】:2017-12-24 11:40:24
【问题描述】:
我在 TFS 存储库中维护我的 Powershell 脚本文件和 SQL 文件。我正在尝试从 Powershell 脚本(也位于 TFS 中)准备我的 SQL 文件。我在我的构建中调用了这个 powershell 脚本。执行时出现错误。
$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 的日志以了解失败的登录尝试。
标签: sql powershell visual-studio-2012 tfs continuous-deployment