Answer the question
In order to leave comments, you need to log in
How to correctly set parameters in a request?
There is a connection to the database, the request is working, there is a table in that database, everything for connecting to the database and sending the request is configured correctly, as I understand it. But why can't I substitute the variable value into the query, what am I doing wrong?
added later:
I temporarily solved this problem like this: in the script I simply dynamically generate a request, I substitute all the parameters in it directly into the request text. That's how it worked.
private const string NotifyManagerTimestampName = "NotifyManagerTimestamp";
private const string SqlNotifyManagerTimestamp = "SqlNotifyManagerTimestamp";
private const string SqlNotifyManagerPattern = @"UPDATE DatetimeStamp SET STAMP = CAST({0} AS DATETIME2) WHERE NAME = 'SsisTestManager';";
/// <summary>
/// This method is called when this script task executes in the control flow.
/// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
/// To open Help, press F1.
/// </summary>
public void Main()
{
try
{
DateTime now = DateTime.Now;
string nowParam = "'" + now.Year + now.Month.ToString("00") + now.Day.ToString("00") + "'";
string result = string.Format(SqlNotifyManagerPattern, nowParam);
Dts.Variables[NotifyManagerTimestampName].Value = now;
Dts.Variables[SqlNotifyManagerTimestamp].Value = result;
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception)
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
UPDATE DatetimeStamp SET STAMP = CAST([NotifyManagerTimestamp] AS DATETIME2)
WHERE NAME = 'SsisTestManager';
Answer the question
In order to leave comments, you need to log in
1) Why write in []?
2) Please show how your SQL query is formed and called
The fact that you are making a request means the following:
For the STAMP field,
take the value from the [NotifyManagerTimestamp] field
Therefore, the error. They write to you about it: such a field was not found. If you want to use a variable, then it's like this: @NotifyManagerTimestamp
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question