我需要使用文本文件更新表格。目前,如果我Get-Content
从 txt 文件执行然后运行 SQL 更新查询,我的代码可以正常工作,但仅限于小数据的情况。如果文本过长或包含一些特殊字符,则会抛出如下错误:
使用“0”参数调用“ExecuteReader”的异常:“附近的语法不正确 ')</td><td style=\"border:1px solid #cccccc\">#fieldValueEmpty($issue.getCustom 字段值($componentTypeCf),'。” 在 C:\Users\d-mansings\Desktop\Scripted Field Configuration\Script\Prod_UpdateS cript.ps1:78 字符:37 + $Reader = $Command.ExecuteReader <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException +fullyQualifiedErrorId:DotNetMethodException
以下是我正在使用的代码:
Function DatabaseQueries(){
#To connect to the SQL database
$Connection = New-Object System.Data.SQLClient.SQLConnection
$Connection.ConnectionString = "Server=$IPSource ; Database=$DBNameSource ; User ID=$UserIDSource ; Password=$LoginPwdSource;"
$Connection.Open()
#Query to get the ID of the stored script field from propertyentry
$Command1 = New-Object System.Data.SQLClient.SQLCommand
$Command1.Connection = $Connection
$Command1.CommandText = "SELECT [ID] FROM [dbo].[propertyentry] WHERE [PROPERTY_KEY]='com.onresolve.jira.groovy.groovyrunner:customfields' "
$Reader = $Command1.ExecuteReader()
while ($Reader.Read()) {
$ID = $Reader.GetValue($1)
}
#To get the updated script file
$ScriptDir = $ParentDir + '\Script.txt'
$ScriptData = Get-Content "$ScriptDir"
$Connection.Close()
#Query to update the Script in JIRA database
$Connection.Open()
$Command = New-Object System.Data.SQLClient.SQLCommand
$Command.Connection = $Connection
$Command.CommandText = @"
Update [dbo].[propertytext] set [propertyvalue] ='$ScriptData' Where ID=$ID
"@
$Reader = $Command.ExecuteReader()
$Connection.Close()
}