title: Using Connection manager in script task in ssis 2008
body: <p>I have made ssis package where in I have taken Script task and by using that script task I am taking count from one of the Database table and sending that count in mail. Now,in that script task,if I take connection from variable ,it works. But I want to take connection directly from connection manager but it is not working. Please suggest on the same.Below is code snippet I have used.</p>
  
  <pre><code>    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 :" &amp; a &amp; ""
      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
  </code></pre>