-
Notifications
You must be signed in to change notification settings - Fork 0
/
Handle_Function_Out_Paramater.cs
137 lines (124 loc) · 6.6 KB
/
Handle_Function_Out_Paramater.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#region Namespaces
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Threading;
#endregion
namespace ST_845cb482744b427b8b9e52156c3408fd
{
/// <summary>
/// ScriptMain is the entry point class of the script. Do not change the name, attributes,
/// or parent of this class.
/// </summary>
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
#region Help: Using Integration Services variables and parameters in a script
/* To use a variable in this script, first ensure that the variable has been added to
* either the list contained in the ReadOnlyVariables property or the list contained in
* the ReadWriteVariables property of this script task, according to whether or not your
* code needs to write to the variable. To add the variable, save this script, close this instance of
* Visual Studio, and update the ReadOnlyVariables and
* ReadWriteVariables properties in the Script Transformation Editor window.
* To use a parameter in this script, follow the same steps. Parameters are always read-only.
*
* Example of reading from a variable:
* DateTime startTime = (DateTime) Dts.Variables["System::StartTime"].Value;
*
* Example of writing to a variable:
* Dts.Variables["User::myStringVariable"].Value = "new value";
*
* Example of reading from a package parameter:
* int batchId = (int) Dts.Variables["$Package::batchId"].Value;
*
* Example of reading from a project parameter:
* int batchId = (int) Dts.Variables["$Project::batchId"].Value;
*
* Example of reading from a sensitive project parameter:
* int batchId = (int) Dts.Variables["$Project::batchId"].GetSensitiveValue();
* */
#endregion
#region Help: Firing Integration Services events from a script
/* This script task can fire events for logging purposes.
*
* Example of firing an error event:
* Dts.Events.FireError(18, "Process Values", "Bad value", "", 0);
*
* Example of firing an information event:
* Dts.Events.FireInformation(3, "Process Values", "Processing has started", "", 0, ref fireAgain)
*
* Example of firing a warning event:
* Dts.Events.FireWarning(14, "Process Values", "No values received for input", "", 0);
* */
#endregion
#region Help: Using Integration Services connection managers in a script
/* Some types of connection managers can be used in this script task. See the topic
* "Working with Connection Managers Programatically" for details.
*
* Example of using an ADO.Net connection manager:
* object rawConnection = Dts.Connections["Sales DB"].AcquireConnection(Dts.Transaction);
* SqlConnection myADONETConnection = (SqlConnection)rawConnection;
* //Use the connection in some code here, then release the connection
* Dts.Connections["Sales DB"].ReleaseConnection(rawConnection);
*
* Example of using a File connection manager
* object rawConnection = Dts.Connections["Prices.zip"].AcquireConnection(Dts.Transaction);
* string filePath = (string)rawConnection;
* //Use the connection in some code here, then release the connection
* Dts.Connections["Prices.zip"].ReleaseConnection(rawConnection);
* */
#endregion
/// <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()
{
string SMTPServer = "smtp.com";
string MailFrom = "[email protected]";
string MailTo = "[email protected]";
string MailCC = "[email protected]";
string MailSub = "Summary report - File(s) for processing not available";
BusinessDay(MailFrom, MailTo, MailCC, SMTPServer);
FileExists(MailFrom, MailTo, MailCC, MailSub, SMTPServer);
Dts.TaskResult = (int)ScriptResults.Success;
}
private void BusinessDay(string MailFrom, string MailTo, string MailCC, string SMTPServer)
{
string WorkingDay = Dts.Variables["User::WorkingDay"].Value.ToString();
string Database = Dts.Variables["User::Database"].Value.ToString();
string Server = Dts.Variables["User::Server"].Value.ToString();
string SP = Dts.Variables["User::SP_WorkingDay"].Value.ToString();
//int output = 0;
string SQLConnString = @"Data Source=" + Server + ";Initial Catalog=" + Database + ";Integrated Security=SSPI;";
try
{
SqlConnection SQLCON = new SqlConnection(SQLConnString);
SqlCommand SQLCommand = new SqlCommand(SP, SQLCON);
SQLCommand.CommandType = CommandType.StoredProcedure;
SQLCommand.Parameters.AddWithValue("@DAY", WorkingDay);
SQLCommand.Parameters.Add("@OUTPUT", SqlDbType.Int);
SQLCommand.Parameters["@OUTPUT"].Direction = ParameterDirection.Output;
SQLCON.Open();
SQLCommand.ExecuteNonQuery();
//Dts.Variables["User::IsWorkingDay"].Value = (int)SQLCommand.ExecuteScalar();
SQLCON.Close();
Dts.Variables["User::IsWorkingDay"].Value = Int16.Parse(SQLCommand.Parameters["@OUTPUT"].Value.ToString());
MessageBox.Show(Dts.Variables["User::IsWorkingDay"].Value.ToString());
}
catch (Exception ex)
{
string MailBody, MailSub = "Summary report - Checking Business Day failed";
MailBody = "Hello Team </BR></BR>";
MailBody += string.Format("Checking Business Day faile failed due to:</BR><b>Error message:</b>{1}", ex.Message);
SendMail(MailFrom, MailTo, MailCC, MailSub, SMTPServer, MailBody);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}