我已经制作了 ssis 包,在其中我执行了脚本任务,并通过使用该脚本任务,我从数据库表之一中计数并在邮件中发送该计数。现在,在那个脚本任务中,如果我从变量中获取连接,它就可以工作。但我想直接从连接管理器获取连接,但它不起作用。请提出相同的建议。以下是我使用的代码片段。
Public Sub Main()
Dim str_con As String
str_con = Dts.Connections("INPUND79.Sample.sample").ConnectionString.ToString()
Dim con As New SqlConnection(str_con)
con.Open()
Dim cmd As New SqlCommand("select count(*) from Department", con)
Dim a As Integer = Convert.ToInt32(cmd.ExecuteScalar())
Dim message As String = "Total Number of Records in Department Table is :" & a & ""
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Host = "UKCAMSCAS10.aveva.com"
mail = New MailMessage()
mail.From = New MailAddress("mandar.dandage@aveva.com")
mail.To.Add("mandar.dandage@aveva.com")
mail.Subject = "Count in Table"
mail.Body = message
SmtpServer.Send(mail)
Dts.TaskResult = ScriptResults.Success
End Sub