Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datasets cause SMTP Mail to hang?

Status
Not open for further replies.

ViperPit

Programmer
Aug 4, 2005
30
US
This is really odd, and I'm not how it could even be possible, but here goes...
I have a project that was using ADO Recordsets to perform database tasks, and when the procedure completed it would send an email using the built in System.Web.Mail namespace.
Now the email does not reference any fields or other data from the recordsets, it is simply static text to inform users the process is complete.
Now I have modified the database operations to use ADO.Net Datasets, and now when the call to send the email is invoked, it just hangs on the line to send the email.
Again, the email is simply static text, and has nothing to do with the Datasets, so I'm not sure how this could be affecting it, but it is the only change that has been made to the code since the problem started.
Also, if I step into the procedure and skip all the code that does the Dataset operations and jump down to the code that sends the email, then the email sends fine.
So obviously there has to be something with the Dataset usage that is causing a problem with sending email, but I can't imagine what it could be.
Has anyone ever seen anything like this, or have any ideas on how I can proceed?
I have an error handling Try/Except block in the email subroutine, but it isn't coming back with an error, it is just hanging indefinitely on the line that calls the Send method.

Thanks. :)
 
can we see some code?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Chrissie, here is the code that sends the emails...
Code:
Option Strict Off
Option Explicit On 
Option Compare Text
Imports System
Imports System.IO
Imports System.Text
Imports System.Web

Friend Class SMTPMailer

    Public Sub SendMail(ByRef pFromDisplay As String, ByRef pFrom As String, ByRef pTo As String, ByRef pCC As String, ByRef pBCC As String, ByRef pSubject As String, ByRef pMessage As String, Optional ByRef pReplyTo As String = "")

        Dim email As New System.Web.Mail.MailMessage
        pTo = Replace(pTo, ",", ";")
        pCC = Replace(pCC, ",", ";")
        pBCC = Replace(pBCC, ",", ";")
        With email
            If pFromDisplay Is Nothing Then
                .From = ""
            Else
                .From = """" & pFromDisplay & """" & "<" & pFrom & ">"
            End If
            If pTo Is Nothing Then
                .To = ""
            Else
                .To = pTo
            End If
            If pCC Is Nothing Then
                .Cc = ""
            Else
                .Cc = pCC
            End If
            If pBCC Is Nothing Then
                .Bcc = ""
            Else
                .Bcc = pBCC
            End If
            If pSubject Is Nothing Then
                .Subject = ""
            Else
                .Subject = pSubject
            End If
            If pMessage Is Nothing Then
                .Body = ""
            Else
                .Body = pMessage
            End If

            If pReplyTo <> "" Then
                .Headers.Add("Reply-To", pReplyTo)
            End If
        End With

        Try
            System.Web.Mail.SmtpMail.SmtpServer = "192.168.1.35"
            System.Web.Mail.SmtpMail.Send(email)
        Catch ehttp As System.Web.HttpException
            Console.WriteLine("0", ehttp.Message)
            Console.WriteLine("Here is the full error message")
            Console.Write("0", ehttp.ToString())
        End Try
    End Sub
End Class

And here is the procedure that is calling it.
I have highlighted the specific call in bold.
Code:
Option Strict Off
Option Explicit On 

Imports VB = Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Imports Ras
Imports TAPI3Lib
Imports System.Data.SqlClient

Module UpgradeSupport
    Friend AccessApplication_definst As New Access.Application
    Friend DAODBEngine_definst As New DAO.DBEngine
End Module

    Public Sub Template_Picker(ByRef pChannelID As Short, ByRef pChannelType As Short, ByRef pMaxVersionOnly As Boolean)
        On Error GoTo Template_Picker_ERROR

        Dim MySQL As String
        Dim MyCommand As SqlCommand
        Dim MyCommandExec As SqlCommand

        Dim MyAdaptor1 As SqlDataAdapter
        Dim MyDataset1 As DataSet
        Dim MyDataRow1 As DataRow

        Dim MyAdaptor2 As SqlDataAdapter
        Dim MyDataset2 As DataSet
        Dim MyDataRow2 As DataRow

        Dim MyAdaptor3 As SqlDataAdapter
        Dim MyDataset3 As DataSet
        Dim MyDataRow3 As DataRow

        Dim MyLockedAdaptor As SqlDataAdapter
        Dim MyLockedDataset As DataSet
        Dim MyLockedDataRow As DataRow

        Dim mDay As Short 'DOW Sunday = 1
        Dim mHour As Short 'hour of the day
        Dim mSlot As Short 'slot for the day

        Dim mRecCount As Short
        Dim mArrayPos As Short 'where to insert next record into array
        Dim mTry As Short
        Dim mRevNum As Integer
        Dim i As Short
        Dim varNeedToPick As Boolean
        Dim varLibCount As Short

        Dim mTemplateHour As Short 'hour of template
        Dim mGotOne As Boolean

        'Dim mContentArray(3, 16, 1, 5) 'Holds Content Info for Template Slots
        '3 = Hours
        '16 = Slots
        '1 = Content (redimensioned below based on library totals)
        '4 = Properties
        'Index
        '0 = Content
        '1 = Artist
        '2 = Rating
        '3 = Audio Rating
        '4 = template_playback_category_id
        '5 = Has it been considered


        'Dim mBinArray(6, 2687) 'will hold an entire week's detail
        '0 = day
        '1 = hour
        '2 = slot
        '3 = content_id
        '4 = artist_id
        '5 = rating_id
        '6 = audio_rating_id

        If pMaxVersionOnly = True Then
            MySQL = ""
            MySQL = MySQL & " SELECT max(version_number) As version_number, primary_bin_group_id, library_id"
            MySQL = MySQL & " FROM tbl_channel_bin_group_versions, tbl_channel_bin_groups"
            MySQL = MySQL & " WHERE tbl_channel_bin_group_versions.channel_id = tbl_channel_bin_groups.channel_id"
            MySQL = MySQL & " AND tbl_channel_bin_group_versions.channel_id = " & pChannelID
            MySQL = MySQL & " GROUP BY primary_bin_group_id, library_id"
        Else
            MySQL = ""
            MySQL = MySQL & " SELECT version_number, primary_bin_group_id, library_id"
            MySQL = MySQL & " FROM tbl_channel_bin_group_versions, tbl_channel_bin_groups"
            MySQL = MySQL & " WHERE tbl_channel_bin_group_versions.channel_id = tbl_channel_bin_groups.channel_id"
            MySQL = MySQL & " AND tbl_channel_bin_group_versions.channel_id = " & pChannelID
            MySQL = MySQL & " ORDER BY version_number DESC"
        End If

        'MyRST1.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
        MyCommand = New SqlCommand(MySQL, gDBCon)
        MyAdaptor1 = New SqlDataAdapter(MyCommand)
        MyDataset1 = New DataSet
        MyAdaptor1.Fill(MyDataset1, "DataTable")
        MyCommand.Dispose()

        For Each MyDataRow1 In MyDataset1.Tables("DataTable").Rows 'Do While Not MyRST1.EOF
            mDay = 1
            mHour = 0
            mArrayPos = 0

            'See if there are any clubs at or below this version, to see if it needs picked
            If pMaxVersionOnly = True Then
                varNeedToPick = True
            Else
                MySQL = ""
                MySQL = MySQL & " SELECT server_install_id"
                MySQL = MySQL & " FROM tbl_server_installs"
                MySQL = MySQL & " WHERE base_library_id = " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                MySQL = MySQL & " AND base_version_number <= " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                MySQL = MySQL & " AND status_id In (1,2,10,13)"

                MyCommand = New SqlCommand(MySQL, gDBCon)
                MyAdaptor2 = New SqlDataAdapter(MyCommand)
                MyDataset2 = New DataSet
                MyAdaptor2.Fill(MyDataset2, "DataTable")
                MyCommand.Dispose()
                'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
                    varNeedToPick = False
                Else
                    varNeedToPick = True
                End If
                MyDataset2.Dispose() 'MyRST2.Close()
                MyAdaptor2.Dispose()
            End If

            If varNeedToPick = True Then
                MySQL = ""
                MySQL = MySQL & " SELECT MAX(revision_number) as MaxRev"
                MySQL = MySQL & " FROM tbl_bin_group_versions"
                MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
                MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value

                MyCommand = New SqlCommand(MySQL, gDBCon)
                MyAdaptor2 = New SqlDataAdapter(MyCommand)
                MyDataset2 = New DataSet
                MyAdaptor2.Fill(MyDataset2, "DataTable")
                MyCommand.Dispose()
                'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
                    'Create Rev Zero, then Pick Rev One
                    MySQL = ""
                    MySQL = MySQL & " INSERT INTO tbl_bin_group_versions"
                    MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number, bin_group_type_id, picked)"
                    MySQL = MySQL & " VALUES"
                    MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & "," 'MyRST1.Fields("primary_bin_group_id").Value & ", "
                    MySQL = MySQL & MyDataRow1("library_id") & "," 'MyRST1.Fields("library_id").Value & ", "
                    MySQL = MySQL & MyDataRow1("version_number") & "," 'MyRST1.Fields("version_number").Value & ", "
                    MySQL = MySQL & "0,1,0)"

                    MyCommandExec = New SqlCommand(MySQL, gDBCon)
                    MyCommandExec.ExecuteNonQuery()
                    MyCommandExec.Dispose()
                    'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                    mRevNum = 1
                Else
                    MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
                    If IsDBNull(MyDataRow2("MaxRev")) Then 'MyRST2.Fields("MaxRev").Value) Then
                        'Create Rev Zero, then Pick Rev One
                        MySQL = ""
                        MySQL = MySQL & " INSERT INTO tbl_bin_group_versions"
                        MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number, bin_group_type_id, picked)"
                        MySQL = MySQL & " VALUES"
                        MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & "," 'MyRST1.Fields("primary_bin_group_id").Value & ", "
                        MySQL = MySQL & MyDataRow1("library_id") & "," 'MyRST1.Fields("library_id").Value & ", "
                        MySQL = MySQL & MyDataRow1("version_number") & "," 'MyRST1.Fields("version_number").Value & ", "
                        MySQL = MySQL & "0,1,0)"

                        MyCommandExec = New SqlCommand(MySQL, gDBCon)
                        MyCommandExec.ExecuteNonQuery()
                        MyCommandExec.Dispose()
                        'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                        mRevNum = 1
                    Else
                        mRevNum = AccessApplication_definst.Nz(MyDataRow2("MaxRev") + 1) 'MyRST2.Fields("MaxRev").Value + 1)
                    End If
                End If
                MyDataset2.Dispose() 'MyRST2.Close()
                MyAdaptor2.Dispose()

                MySQL = ""
                MySQL = MySQL & " INSERT INTO tbl_bin_group_versions"
                MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number, bin_group_type_id, picked)"
                MySQL = MySQL & " VALUES"
                MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & "," 'MyRST1.Fields("primary_bin_group_id").Value & ", "
                MySQL = MySQL & MyDataRow1("library_id") & "," 'MyRST1.Fields("library_id").Value & ", "
                MySQL = MySQL & MyDataRow1("version_number") & "," 'MyRST1.Fields("version_number").Value & ", "
                MySQL = MySQL & mRevNum & ",1,1)"

                MyCommandExec = New SqlCommand(MySQL, gDBCon)
                MyCommandExec.ExecuteNonQuery()
                MyCommandExec.Dispose()
                'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                'Determine how large to make the array for storing the template content
                MySQL = ""
                MySQL = MySQL & " SELECT count(entertainment_id) As LibCount"
                MySQL = MySQL & " FROM tbl_library_content"
                MySQL = MySQL & " WHERE library_id = " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value

                MyCommand = New SqlCommand(MySQL, gDBCon)
                MyAdaptor2 = New SqlDataAdapter(MyCommand)
                MyDataset2 = New DataSet
                MyAdaptor2.Fill(MyDataset2, "DataTable")
                MyCommand.Dispose()
                'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)

                varLibCount = MyDataRow2("LibCount") 'MyRST2.Fields("LibCount").Value

                MyDataset2.Dispose() 'MyRST2.Close()
                MyAdaptor2.Dispose()

                Dim mContentArray(3, 16, varLibCount, 5) As Object 'will hold all content for the template
                Dim mBinArray(6, 2687) As Object 'Clear out Bin Array

                CType(fMainForm, frmPLUpload).pgBar.Value = 0
                CType(fMainForm, frmPLUpload).pgBar.Max = 48

                For mTemplateHour = 1 To 3
                    For mSlot = 1 To 16
                        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | ContentArray - Hour:" & mTemplateHour & " Slot:" & mSlot
                        CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
                        CType(fMainForm, frmPLUpload).Refresh()

                        'Get The Criteria For the Given Slot
                        Select Case pChannelType
                            Case 2 'Template
                                MySQL = ""
                                MySQL = MySQL & " SELECT tbl_channel_templates.genre_id, tbl_template_playback_category_def.template_playback_category_id,"
                                MySQL = MySQL & "        tbl_template_playback_category_def.template_playback_category_sql,"
                                MySQL = MySQL & "        tbl_template_energy_def.template_energy_sql,"
                                MySQL = MySQL & "        tbl_template_age_def.template_age_sql,"
                                MySQL = MySQL & "        tbl_template_audio_rating_def.template_audio_rating_sql,"
                                MySQL = MySQL & "        tbl_template_video_rating_def.template_video_rating_sql"
                                MySQL = MySQL & " FROM   tbl_channel_templates, tbl_template_playback_category_def,"
                                MySQL = MySQL & "        tbl_template_energy_def, tbl_template_age_def,"
                                MySQL = MySQL & "        tbl_template_audio_rating_def, tbl_template_video_rating_def"
                                MySQL = MySQL & " WHERE  tbl_channel_templates.template_playback_category_id = tbl_template_playback_category_def.template_playback_category_id"
                                MySQL = MySQL & " AND    tbl_channel_templates.template_energy_id = tbl_template_energy_def.template_energy_id"
                                MySQL = MySQL & " AND    tbl_channel_templates.template_age_id = tbl_template_age_def.template_age_id"
                                MySQL = MySQL & " AND    tbl_channel_templates.template_audio_rating_id = tbl_template_audio_rating_def.template_audio_rating_id"
                                MySQL = MySQL & " AND    tbl_channel_templates.template_video_rating_id = tbl_template_video_rating_def.template_video_rating_id"
                                MySQL = MySQL & " AND    tbl_channel_templates.channel_id = " & pChannelID
                                MySQL = MySQL & " AND    tbl_channel_templates.version_number = " & MyDataRow1("version_number") ' MyRST1.Fields("version_number").Value
                                MySQL = MySQL & " AND    tbl_channel_templates.ch_hour = " & mTemplateHour
                                MySQL = MySQL & " AND    tbl_channel_templates.ch_slot = " & mSlot
                            Case 3, 4 'Facility Specific or User Defined
                                MySQL = ""
                                MySQL = MySQL & " SELECT tbl_template_playback_category_def.user_template_playback_category_sql"
                                MySQL = MySQL & " FROM   tbl_channel_user_templates, tbl_template_playback_category_def"
                                MySQL = MySQL & " WHERE  tbl_channel_user_templates.template_playback_category_id = tbl_template_playback_category_def.template_playback_category_id"
                                MySQL = MySQL & " AND    tbl_channel_user_templates.channel_id = " & pChannelID
                                MySQL = MySQL & " AND    tbl_channel_user_templates.version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                                MySQL = MySQL & " AND    tbl_channel_user_templates.ch_hour = " & mTemplateHour
                                MySQL = MySQL & " AND    tbl_channel_user_templates.ch_slot = " & mSlot
                        End Select

                        MyCommand = New SqlCommand(MySQL, gDBCon)
                        MyAdaptor2 = New SqlDataAdapter(MyCommand)
                        MyDataset2 = New DataSet
                        MyAdaptor2.Fill(MyDataset2, "DataTable")
                        MyCommand.Dispose()
                        'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                        If MyDataset2.Tables("DataTable").Rows.Count > 0 Then 'If Not MyRST2.EOF Then
                            MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
                            'Get The Content That Meets the Criteria
                            Select Case pChannelType
                                Case 2 'Template
                                    MySQL = ""
                                    MySQL = MySQL & " SELECT tbl_entertainment.content_id, tbl_entertainment.artist_id, "
                                    MySQL = MySQL & " tbl_entertainment.rating_id , tbl_entertainment.audio_rating_id"
                                    MySQL = MySQL & " FROM tbl_channel_templates"
                                    MySQL = MySQL & " INNER JOIN tbl_channel_bin_groups"
                                    MySQL = MySQL & " ON tbl_channel_templates.channel_id = tbl_channel_bin_groups.channel_id"
                                    MySQL = MySQL & " INNER JOIN tbl_library_content"
                                    MySQL = MySQL & " ON tbl_channel_bin_groups.library_id = tbl_library_content.library_id"
                                    MySQL = MySQL & " AND tbl_channel_templates.version_number = tbl_library_content.version_number"
                                    MySQL = MySQL & " INNER JOIN tbl_entertainment"
                                    MySQL = MySQL & " ON tbl_library_content.entertainment_id = tbl_entertainment.entertainment_id"
                                    If Not IsDBNull(MyDataRow2("genre_id")) Then
                                        MySQL = MySQL & " AND tbl_channel_templates.genre_id = tbl_library_content.genre_id"
                                    End If
                                    MySQL = MySQL & " AND    tbl_channel_templates.channel_id = " & pChannelID
                                    MySQL = MySQL & " AND    tbl_channel_templates.version_number = " & MyDataRow1("version_number")
                                    MySQL = MySQL & " AND    tbl_channel_templates.ch_hour = " & mTemplateHour
                                    MySQL = MySQL & " AND    tbl_channel_templates.ch_slot = " & mSlot
                                    MySQL = MySQL & " AND    tbl_library_content.suppress = 0" 'non suppressed songs
                                    MySQL = MySQL & " AND    tbl_entertainment.no_play = 0" 'not disabled songs
                                    If Not IsDBNull(MyDataRow2("template_playback_category_sql")) Then
                                        MySQL = MySQL & " " & MyDataRow2("template_playback_category_sql")
                                    End If
                                    If Not IsDBNull(MyDataRow2("template_energy_sql")) Then
                                        MySQL = MySQL & " " & MyDataRow2("template_energy_sql")
                                    End If
                                    If Not IsDBNull(MyDataRow2("template_age_sql")) Then
                                        MySQL = MySQL & " " & MyDataRow2("template_age_sql")
                                    End If
                                    If Not IsDBNull(MyDataRow2("template_audio_rating_sql")) Then
                                        MySQL = MySQL & " " & MyDataRow2("template_audio_rating_sql")
                                    End If
                                    If Not IsDBNull(MyDataRow2("template_video_rating_sql")) Then
                                        MySQL = MySQL & " " & MyDataRow2("template_video_rating_sql")
                                    End If
                                Case 3, 4 'Facility Specific or User Defined
                                    MySQL = ""
                                    MySQL = MySQL & " SELECT tbl_entertainment.content_id, tbl_entertainment.artist_id, tbl_entertainment.rating_id, tbl_entertainment.audio_rating_id"
                                    MySQL = MySQL & " FROM   tbl_channel_user_templates, tbl_channel_bin_groups, tbl_library_content, tbl_entertainment, tbl_channel_user_categorization"
                                    MySQL = MySQL & " WHERE  tbl_channel_user_templates.channel_id = tbl_channel_bin_groups.channel_id"
                                    MySQL = MySQL & " AND    tbl_channel_user_templates.version_number = tbl_library_content.version_number"
                                    MySQL = MySQL & " AND    tbl_channel_bin_groups.library_id = tbl_library_content.library_id"
                                    MySQL = MySQL & " AND    tbl_library_content.entertainment_id = tbl_entertainment.entertainment_id"
                                    MySQL = MySQL & " AND    tbl_channel_user_categorization.channel_id = tbl_channel_user_templates.channel_id"
                                    MySQL = MySQL & " AND    tbl_channel_user_categorization.version_number = tbl_channel_user_templates.version_number"
                                    MySQL = MySQL & " AND    tbl_channel_user_categorization.content_id = tbl_entertainment.content_id"
                                    MySQL = MySQL & " AND    tbl_channel_user_templates.channel_id = " & pChannelID
                                    MySQL = MySQL & " AND    tbl_channel_user_templates.version_number = " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                                    MySQL = MySQL & " AND    tbl_channel_user_templates.ch_hour = " & mTemplateHour
                                    MySQL = MySQL & " AND    tbl_channel_user_templates.ch_slot = " & mSlot
                                    MySQL = MySQL & " AND    tbl_library_content.suppress = 0" 'non suppressed songs
                                    MySQL = MySQL & " AND    tbl_entertainment.no_play = 0" 'not disabled songs
                                    If Not IsDBNull(MyDataRow2("user_template_playback_category_sql")) Then
                                        MySQL = MySQL & " " & MyDataRow2("user_template_playback_category_sql")
                                    End If
                            End Select

                            MyCommand = New SqlCommand(MySQL, gDBCon)
                            MyAdaptor3 = New SqlDataAdapter(MyCommand)
                            MyDataset3 = New DataSet
                            MyAdaptor3.Fill(MyDataset3, "DataTable")
                            MyCommand.Dispose()
                            'MyRST3.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                            If MyDataset3.Tables("DataTable").Rows.Count = 0 Then 'If MyRST3.EOF Then
                                'No content found for template
                                varFromDisplay = "Playlist Server"
                                varFrom = "playlist@clubcom.com"
                                varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                                varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                                varBCC = ""
                                varSubject = "Template Picker Failure"
                                varMessage = ""
                                varMessage = varMessage & "Template Picking has failed for the following:"
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Channel ID# " & pChannelID
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Library ID# " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Version # " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Revision # " & mRevNum
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "No valid content was found for template hour #" & mTemplateHour & " and slot #" & mSlot
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & gPLServer

                                Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                                gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                                gLogFile.Flush()

                                MyDataset3.Dispose()
                                MyAdaptor3.Dispose()
                                MyDataset2.Dispose()
                                MyAdaptor2.Dispose()
                                MyDataset1.Dispose()
                                MyAdaptor1.Dispose()
                                'MyRST3.Close()
                                'MyRST2.Close()
                                'MyRST1.Close()
                                Exit Sub
                            End If

                            'MyRST3.MoveLast()
                            'mRecCount = MyRST3.RecordCount
                            'MyRST3.MoveFirst()
                            mRecCount = MyDataset3.Tables("DataTable").Rows.Count
                            mContentArray(mTemplateHour, mSlot, 0, 0) = mRecCount

                            i = 1
                            For Each MyDataRow3 In MyDataset3.Tables("DataTable").Rows 'Do While Not MyRST3.EOF
                                mContentArray(mTemplateHour, mSlot, i, 0) = MyDataRow3("content_id") 'MyRST3.Fields("content_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 1) = MyDataRow3("artist_id") 'MyRST3.Fields("artist_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 2) = MyDataRow3("rating_id") 'MyRST3.Fields("rating_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 3) = MyDataRow3("audio_rating_id") 'MyRST3.Fields("audio_rating_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 4) = False 'used to keep track of what songs have been tested for validity
                                If pChannelType = 2 Then
                                    mContentArray(mTemplateHour, mSlot, i, 5) = MyDataRow2("template_playback_category_id") 'MyRST2.Fields("template_playback_category_id").Value
                                Else
                                    mContentArray(mTemplateHour, mSlot, i, 5) = 0
                                End If

                                i = i + 1
                                'MyRST3.MoveNext()
                            Next MyDataRow3
                            MyDataset3.Dispose()
                            MyAdaptor3.Dispose()
                            'MyRST3.Close()
                        Else
                            'No template defined
                            varFromDisplay = "Playlist Server"
                            varFrom = "playlist@clubcom.com"
                            varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                            varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                            varBCC = ""
                            varSubject = "Template Picker Failure"
                            varMessage = ""
                            varMessage = varMessage & "Template Picking has failed for the following:"
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Channel ID# " & pChannelID
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Library ID# " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Version # " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Revision # " & mRevNum
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "No template defined for hour #" & mTemplateHour & " and slot #" & mSlot
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & gPLServer

                            Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                            gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                            gLogFile.Flush()

                            MyDataset2.Dispose()
                            MyAdaptor2.Dispose()
                            MyDataset1.Dispose()
                            MyAdaptor1.Dispose()
                            'MyRST2.Close()
                            'MyRST1.Close()
                            Exit Sub
                        End If
                        MyDataset2.Dispose()
                        MyAdaptor2.Dispose()
                        'MyRST2.Close()
                    Next mSlot
                Next mTemplateHour

                CType(fMainForm, frmPLUpload).pgBar.Value = 0
                CType(fMainForm, frmPLUpload).pgBar.Max = 168

                For mDay = 1 To 7
                    mHour = 0
                    Do While mHour <= 23
                        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | BinArray - Day:" & mDay & " Hour:" & mHour
                        CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
                        CType(fMainForm, frmPLUpload).Refresh()

                        Select Case mHour
                            Case 0, 3, 6, 9, 12, 15, 18, 21
                                mTemplateHour = 1
                            Case 1, 4, 7, 10, 13, 16, 19, 22
                                mTemplateHour = 2
                            Case 2, 5, 8, 11, 14, 17, 20, 23
                                mTemplateHour = 3
                        End Select

                        For mSlot = 1 To 16
                            mRecCount = mContentArray(mTemplateHour, mSlot, 0, 0) 'contains the number of songs in this hour/slot

                            Randomize() 'initialize seed with current time
                            mTry = 0
                            Do While True
                                i = Int((mRecCount - 1 + 1) * Rnd() + 1)
                                '   Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
                                If mContentArray(mTemplateHour, mSlot, i, 4) = False Then 'We have not already tried this item, so try it
                                    If IsValidTemplateContent(mBinArray, mArrayPos, mDay, mHour, mSlot, mContentArray(mTemplateHour, mSlot, i, 0), mContentArray(mTemplateHour, mSlot, i, 1)) Then 'add it
                                        Exit Do
                                    End If
                                End If
                                mContentArray(mTemplateHour, mSlot, i, 4) = True 'tested this item for validity

                                mTry = mTry + 1
                                If mTry = mRecCount * 2 Then
                                    mGotOne = False
                                    For i = 1 To mRecCount
                                        If mContentArray(mTemplateHour, mSlot, i, 4) = False Then 'Check ones that we have not tried yet if there are any
                                            If IsValidTemplateContent(mBinArray, mArrayPos, mDay, mHour, mSlot, mContentArray(mTemplateHour, mSlot, i, 0), mContentArray(mTemplateHour, mSlot, i, 1)) Then 'add it
                                                mGotOne = True
                                                Exit For 'becase we found one that works which wasn't randomly picked
                                            End If
                                            'mContentArray(mTemplateHour, mSlot, i, 4) = True 'tested this item for validity
                                            'Don't really need to update this since I checked it once and won't check it again because "i" gets incremented in the FOR loop
                                        End If
                                    Next i
                                    If mGotOne Then Exit Do 'else we didn't get one randomly AND we didn't get one stepping through the array so give up

                                    If pChannelType <> 4 And mContentArray(mTemplateHour, mSlot, 1, 5) <> 8 Then 'If the 1st song's template playback category is D then ignore the rules
                                        'No content found for template
                                        varFromDisplay = "Playlist Server"
                                        varFrom = "playlist@clubcom.com"
                                        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                                        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                                        varBCC = ""
                                        varSubject = "Template Picker Failure"
                                        varMessage = ""
                                        varMessage = varMessage & "Template Picking has failed for the following:"
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Channel ID# " & pChannelID
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Revision # " & mRevNum
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "No valid content was found for template hour #" & mTemplateHour & " and slot #" & mSlot & "."
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & gPLServer
                                        Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)

                                        Exit Sub
                                    Else
                                        i = Int((mRecCount - 1 + 1) * Rnd() + 1)
                                        '   Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
                                        Exit Do
                                        'This is because pChannelType of 4 (user defined) might not have enough songs classified
                                        'to pick using our standard rules
                                        'NOTE: This may take a long time because we'll try mRecCount*2 and then fail
                                    End If
                                End If
                            Loop
                            'we have a Valid Content_Id to add to the bin array
                            mBinArray(0, mArrayPos) = mDay
                            mBinArray(1, mArrayPos) = mHour
                            mBinArray(2, mArrayPos) = mSlot
                            If IsDBNull(mContentArray(mTemplateHour, mSlot, i, 0)) Then
                                Call MsgBox("No Content ID, something is very wrong!")
                            ElseIf mContentArray(mTemplateHour, mSlot, i, 0) Is Nothing Then
                                Call MsgBox("No Content ID, something is very wrong!")
                            Else
                                mBinArray(3, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 0)
                            End If
                            mBinArray(4, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 1)
                            mBinArray(5, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 2)
                            mBinArray(6, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 3)
                            mArrayPos = mArrayPos + 1

                        Next mSlot
                        mHour = mHour + 1
                    Loop
                Next mDay

                If mArrayPos > 0 Then 'Insert Array Data into tbl_bin_group_detail
                    CType(fMainForm, frmPLUpload).pgBar.Value = 0
                    CType(fMainForm, frmPLUpload).pgBar.Max = 2688

                    For i = 0 To 2687
                        CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
                        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | Table - " & i
                        CType(fMainForm, frmPLUpload).Refresh()

                        MySQL = ""
                        MySQL = MySQL & " INSERT INTO tbl_bin_group_detail"
                        MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number,"
                        MySQL = MySQL & " schedule_day, schedule_hour, schedule_slot, content_id, rating_id, audio_rating_id,"
                        MySQL = MySQL & " scheduled_type_id, scheduled_date, scheduled_user)"
                        MySQL = MySQL & " VALUES"
                        MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & ", "
                        MySQL = MySQL & MyDataRow1("library_id") & ", "
                        MySQL = MySQL & MyDataRow1("version_number") & ", "
                        MySQL = MySQL & mRevNum & ", "
                        MySQL = MySQL & mBinArray(0, i) & ", " 'Day
                        MySQL = MySQL & mBinArray(1, i) & ", " 'Hour
                        MySQL = MySQL & mBinArray(2, i) & ", " 'Slot
                        MySQL = MySQL & mBinArray(3, i) & ", " 'Content_id
                        MySQL = MySQL & mBinArray(5, i) & ", " 'Rating
                        MySQL = MySQL & mBinArray(6, i) & ", " 'Audio_Rating
                        MySQL = MySQL & "2, '" & Today & "', '" & gPLServer & "')"

                        MyCommandExec = New SqlCommand(MySQL, gDBCon)
                        MyCommandExec.ExecuteNonQuery()
                        MyCommandExec.Dispose()
                        'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                        mBinArray(0, i) = 0
                        mBinArray(1, i) = 0
                        mBinArray(2, i) = 0
                        mBinArray(3, i) = 0
                        mBinArray(4, i) = 0
                        mBinArray(5, i) = 0
                        mBinArray(6, i) = 0
                    Next i
                End If

                MySQL = ""
                MySQL = MySQL & " SELECT Count(content_id) AS ContentCount"
                MySQL = MySQL & " FROM tbl_bin_group_detail"
                MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id")
                MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id")
                MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number")
                MySQL = MySQL & " AND revision_number = " & mRevNum

                MyCommand = New SqlCommand(MySQL, gDBCon)
                MyAdaptor2 = New SqlDataAdapter(MyCommand)
                MyDataset2 = New DataSet
                MyAdaptor2.Fill(MyDataset2, "DataTable")
                MyCommand.Dispose()
                'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
                    varFromDisplay = "Playlist Server"
                    varFrom = "playlist@clubcom.com"
                    varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                    varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                    varBCC = ""
                    varSubject = "Template Picker Failure"
                    varMessage = ""
                    varMessage = varMessage & "Template Picking has failed for the following:"
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Channel ID# " & pChannelID
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Revision # " & mRevNum
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & gPLServer

                    Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                    gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                    gLogFile.Flush()
                Else
                    MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
                    If MyDataRow2("ContentCount") = 2688 Then 'If MyRST2.Fields("ContentCount").Value = 2688 Then
                        MySQL = ""
                        MySQL = MySQL & " UPDATE tbl_bin_group_versions"
                        MySQL = MySQL & " SET approved = 1, approved_by = 'TemplatePicker', approved_date = '" & Today & "'"
                        MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id")
                        MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id")
                        MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number")
                        MySQL = MySQL & " AND revision_number = " & mRevNum

                        MyCommandExec = New SqlCommand(MySQL, gDBCon)
                        MyCommandExec.ExecuteNonQuery()
                        'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
                    Else
                        varFromDisplay = "Playlist Server"
                        varFrom = "playlist@clubcom.com"
                        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                        varBCC = ""
                        varSubject = "Template Picker Failure"
                        varMessage = ""
                        varMessage = varMessage & "Template Picking has failed for the following:"
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Channel ID# " & pChannelID
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Revision # " & mRevNum
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & gPLServer

                        Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                        gLogFile.Flush()
                    End If
                End If
                MyDataset2.Dispose()
                MyAdaptor2.Dispose()
                'MyRST2.Close()
            End If 'End NeedToPick
            'MyRST1.MoveNext()
        Next MyDataRow1  'while not myRst1.eof
        MyDataset1.Dispose()
        MyAdaptor1.Dispose()
        'MyRST1.Close()

        varFromDisplay = "Playlist Server"
        varFrom = "playlist@clubcom.com"
        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
        varBCC = ""
        varSubject = "Template Picker Notification"
        varMessage = ""
        varMessage = varMessage & "Channel Templates have been picked for Channel ID# " & pChannelID
        varMessage = varMessage & vbCrLf
        varMessage = varMessage & vbCrLf
        varMessage = varMessage & gPLServer

        [b]Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)[/b]
        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Channel Templates have been picked for Channel ID# " & pChannelID)
        gLogFile.Flush()

        CType(fMainForm, frmPLUpload).pgBar.Value = 0
        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "RUNNING..."
        CType(fMainForm, frmPLUpload).Refresh()

        GoTo Template_Picker_EXIT

Template_Picker_ERROR:
        If File.Exists("C:\SERVER_ALIVE") = True Then
            Kill("C:\SERVER_ALIVE")
        End If
        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "ERROR: " & Err.Number & " - " & Err.Description)
        gLogFile.Flush()
        Call MsgBox("ERROR: " & Err.Number & " - " & Err.Description, MsgBoxStyle.Critical)
        Resume

Template_Picker_EXIT:

    End Sub

If I come into this procedure and break the code at the first line:
If pMaxVersionOnly = True Then
and then jump down to the call to send the email, then the email sends fine.
If the procedure runs normally and then calls the send mail procedure, then it hangs. Adn if I pause the execution, it is stuck on the line:
System.Web.Mail.SmtpMail.Send(email)
And it is highlighted in Green, indicating the call is processing.
I have let it sit for up to a half an hour and it never returns. When it does work, it returns instantly after calling the Send.
I went through and made sure I disposed of all the datasets and adaptors I was using (not that it should cause this problem). I'm kind of at a loss right now.

Any ideas are appreciated. Thanks. :)
 
It looks like my post got cut off, here is the rest of it from where it left off...

Code:
                                varMessage = varMessage & "Channel ID# " & pChannelID
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Library ID# " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Version # " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Revision # " & mRevNum
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & "No valid content was found for template hour #" & mTemplateHour & " and slot #" & mSlot
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & vbCrLf
                                varMessage = varMessage & gPLServer

                                Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                                gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                                gLogFile.Flush()

                                MyDataset3.Dispose()
                                MyAdaptor3.Dispose()
                                MyDataset2.Dispose()
                                MyAdaptor2.Dispose()
                                MyDataset1.Dispose()
                                MyAdaptor1.Dispose()
                                'MyRST3.Close()
                                'MyRST2.Close()
                                'MyRST1.Close()
                                Exit Sub
                            End If

                            'MyRST3.MoveLast()
                            'mRecCount = MyRST3.RecordCount
                            'MyRST3.MoveFirst()
                            mRecCount = MyDataset3.Tables("DataTable").Rows.Count
                            mContentArray(mTemplateHour, mSlot, 0, 0) = mRecCount

                            i = 1
                            For Each MyDataRow3 In MyDataset3.Tables("DataTable").Rows 'Do While Not MyRST3.EOF
                                mContentArray(mTemplateHour, mSlot, i, 0) = MyDataRow3("content_id") 'MyRST3.Fields("content_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 1) = MyDataRow3("artist_id") 'MyRST3.Fields("artist_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 2) = MyDataRow3("rating_id") 'MyRST3.Fields("rating_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 3) = MyDataRow3("audio_rating_id") 'MyRST3.Fields("audio_rating_id").Value
                                mContentArray(mTemplateHour, mSlot, i, 4) = False 'used to keep track of what songs have been tested for validity
                                If pChannelType = 2 Then
                                    mContentArray(mTemplateHour, mSlot, i, 5) = MyDataRow2("template_playback_category_id") 'MyRST2.Fields("template_playback_category_id").Value
                                Else
                                    mContentArray(mTemplateHour, mSlot, i, 5) = 0
                                End If

                                i = i + 1
                                'MyRST3.MoveNext()
                            Next MyDataRow3
                            MyDataset3.Dispose()
                            MyAdaptor3.Dispose()
                            'MyRST3.Close()
                        Else
                            'No template defined
                            varFromDisplay = "Playlist Server"
                            varFrom = "playlist@clubcom.com"
                            varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                            varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                            varBCC = ""
                            varSubject = "Template Picker Failure"
                            varMessage = ""
                            varMessage = varMessage & "Template Picking has failed for the following:"
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Channel ID# " & pChannelID
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Library ID# " & MyDataRow1("library_id") 'MyRST1.Fields("library_id").Value
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Version # " & MyDataRow1("version_number") 'MyRST1.Fields("version_number").Value
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Revision # " & mRevNum
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id") 'MyRST1.Fields("primary_bin_group_id").Value
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & "No template defined for hour #" & mTemplateHour & " and slot #" & mSlot
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & vbCrLf
                            varMessage = varMessage & gPLServer

                            Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                            gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                            gLogFile.Flush()

                            MyDataset2.Dispose()
                            MyAdaptor2.Dispose()
                            MyDataset1.Dispose()
                            MyAdaptor1.Dispose()
                            'MyRST2.Close()
                            'MyRST1.Close()
                            Exit Sub
                        End If
                        MyDataset2.Dispose()
                        MyAdaptor2.Dispose()
                        'MyRST2.Close()
                    Next mSlot
                Next mTemplateHour

                CType(fMainForm, frmPLUpload).pgBar.Value = 0
                CType(fMainForm, frmPLUpload).pgBar.Max = 168

                For mDay = 1 To 7
                    mHour = 0
                    Do While mHour <= 23
                        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | BinArray - Day:" & mDay & " Hour:" & mHour
                        CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
                        CType(fMainForm, frmPLUpload).Refresh()

                        Select Case mHour
                            Case 0, 3, 6, 9, 12, 15, 18, 21
                                mTemplateHour = 1
                            Case 1, 4, 7, 10, 13, 16, 19, 22
                                mTemplateHour = 2
                            Case 2, 5, 8, 11, 14, 17, 20, 23
                                mTemplateHour = 3
                        End Select

                        For mSlot = 1 To 16
                            mRecCount = mContentArray(mTemplateHour, mSlot, 0, 0) 'contains the number of songs in this hour/slot

                            Randomize() 'initialize seed with current time
                            mTry = 0
                            Do While True
                                i = Int((mRecCount - 1 + 1) * Rnd() + 1)
                                '   Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
                                If mContentArray(mTemplateHour, mSlot, i, 4) = False Then 'We have not already tried this item, so try it
                                    If IsValidTemplateContent(mBinArray, mArrayPos, mDay, mHour, mSlot, mContentArray(mTemplateHour, mSlot, i, 0), mContentArray(mTemplateHour, mSlot, i, 1)) Then 'add it
                                        Exit Do
                                    End If
                                End If
                                mContentArray(mTemplateHour, mSlot, i, 4) = True 'tested this item for validity

                                mTry = mTry + 1
                                If mTry = mRecCount * 2 Then
                                    mGotOne = False
                                    For i = 1 To mRecCount
                                        If mContentArray(mTemplateHour, mSlot, i, 4) = False Then 'Check ones that we have not tried yet if there are any
                                            If IsValidTemplateContent(mBinArray, mArrayPos, mDay, mHour, mSlot, mContentArray(mTemplateHour, mSlot, i, 0), mContentArray(mTemplateHour, mSlot, i, 1)) Then 'add it
                                                mGotOne = True
                                                Exit For 'becase we found one that works which wasn't randomly picked
                                            End If
                                            'mContentArray(mTemplateHour, mSlot, i, 4) = True 'tested this item for validity
                                            'Don't really need to update this since I checked it once and won't check it again because "i" gets incremented in the FOR loop
                                        End If
                                    Next i
                                    If mGotOne Then Exit Do 'else we didn't get one randomly AND we didn't get one stepping through the array so give up

                                    If pChannelType <> 4 And mContentArray(mTemplateHour, mSlot, 1, 5) <> 8 Then 'If the 1st song's template playback category is D then ignore the rules
                                        'No content found for template
                                        varFromDisplay = "Playlist Server"
                                        varFrom = "playlist@clubcom.com"
                                        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                                        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                                        varBCC = ""
                                        varSubject = "Template Picker Failure"
                                        varMessage = ""
                                        varMessage = varMessage & "Template Picking has failed for the following:"
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Channel ID# " & pChannelID
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Revision # " & mRevNum
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & "No valid content was found for template hour #" & mTemplateHour & " and slot #" & mSlot & "."
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & vbCrLf
                                        varMessage = varMessage & gPLServer
                                        Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)

                                        Exit Sub
                                    Else
                                        i = Int((mRecCount - 1 + 1) * Rnd() + 1)
                                        '   Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
                                        Exit Do
                                        'This is because pChannelType of 4 (user defined) might not have enough songs classified
                                        'to pick using our standard rules
                                        'NOTE: This may take a long time because we'll try mRecCount*2 and then fail
                                    End If
                                End If
                            Loop
                            'we have a Valid Content_Id to add to the bin array
                            mBinArray(0, mArrayPos) = mDay
                            mBinArray(1, mArrayPos) = mHour
                            mBinArray(2, mArrayPos) = mSlot
                            If IsDBNull(mContentArray(mTemplateHour, mSlot, i, 0)) Then
                                Call MsgBox("No Content ID, something is very wrong!")
                            ElseIf mContentArray(mTemplateHour, mSlot, i, 0) Is Nothing Then
                                Call MsgBox("No Content ID, something is very wrong!")
                            Else
                                mBinArray(3, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 0)
                            End If
                            mBinArray(4, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 1)
                            mBinArray(5, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 2)
                            mBinArray(6, mArrayPos) = mContentArray(mTemplateHour, mSlot, i, 3)
                            mArrayPos = mArrayPos + 1

                        Next mSlot
                        mHour = mHour + 1
                    Loop
                Next mDay

                If mArrayPos > 0 Then 'Insert Array Data into tbl_bin_group_detail
                    CType(fMainForm, frmPLUpload).pgBar.Value = 0
                    CType(fMainForm, frmPLUpload).pgBar.Max = 2688

                    For i = 0 To 2687
                        CType(fMainForm, frmPLUpload).pgBar.Value = CType(fMainForm, frmPLUpload).pgBar.Value + 1
                        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "Picking: Channel - " & pChannelID & " | Library - " & MyDataRow1("library_id") & " | Version - " & MyDataRow1("version_number") & " | Table - " & i
                        CType(fMainForm, frmPLUpload).Refresh()

                        MySQL = ""
                        MySQL = MySQL & " INSERT INTO tbl_bin_group_detail"
                        MySQL = MySQL & " (bin_group_id, library_id, version_number, revision_number,"
                        MySQL = MySQL & " schedule_day, schedule_hour, schedule_slot, content_id, rating_id, audio_rating_id,"
                        MySQL = MySQL & " scheduled_type_id, scheduled_date, scheduled_user)"
                        MySQL = MySQL & " VALUES"
                        MySQL = MySQL & " (" & MyDataRow1("primary_bin_group_id") & ", "
                        MySQL = MySQL & MyDataRow1("library_id") & ", "
                        MySQL = MySQL & MyDataRow1("version_number") & ", "
                        MySQL = MySQL & mRevNum & ", "
                        MySQL = MySQL & mBinArray(0, i) & ", " 'Day
                        MySQL = MySQL & mBinArray(1, i) & ", " 'Hour
                        MySQL = MySQL & mBinArray(2, i) & ", " 'Slot
                        MySQL = MySQL & mBinArray(3, i) & ", " 'Content_id
                        MySQL = MySQL & mBinArray(5, i) & ", " 'Rating
                        MySQL = MySQL & mBinArray(6, i) & ", " 'Audio_Rating
                        MySQL = MySQL & "2, '" & Today & "', '" & gPLServer & "')"

                        MyCommandExec = New SqlCommand(MySQL, gDBCon)
                        MyCommandExec.ExecuteNonQuery()
                        MyCommandExec.Dispose()
                        'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                        mBinArray(0, i) = 0
                        mBinArray(1, i) = 0
                        mBinArray(2, i) = 0
                        mBinArray(3, i) = 0
                        mBinArray(4, i) = 0
                        mBinArray(5, i) = 0
                        mBinArray(6, i) = 0
                    Next i
                End If

                MySQL = ""
                MySQL = MySQL & " SELECT Count(content_id) AS ContentCount"
                MySQL = MySQL & " FROM tbl_bin_group_detail"
                MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id")
                MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id")
                MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number")
                MySQL = MySQL & " AND revision_number = " & mRevNum

                MyCommand = New SqlCommand(MySQL, gDBCon)
                MyAdaptor2 = New SqlDataAdapter(MyCommand)
                MyDataset2 = New DataSet
                MyAdaptor2.Fill(MyDataset2, "DataTable")
                MyCommand.Dispose()
                'MyRST2.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

                If MyDataset2.Tables("DataTable").Rows.Count = 0 Then 'If MyRST2.EOF Then
                    varFromDisplay = "Playlist Server"
                    varFrom = "playlist@clubcom.com"
                    varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                    varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                    varBCC = ""
                    varSubject = "Template Picker Failure"
                    varMessage = ""
                    varMessage = varMessage & "Template Picking has failed for the following:"
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Channel ID# " & pChannelID
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Revision # " & mRevNum
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & vbCrLf
                    varMessage = varMessage & gPLServer

                    Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                    gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                    gLogFile.Flush()
                Else
                    MyDataRow2 = MyDataset2.Tables("DataTable").Rows(0)
                    If MyDataRow2("ContentCount") = 2688 Then 'If MyRST2.Fields("ContentCount").Value = 2688 Then
                        MySQL = ""
                        MySQL = MySQL & " UPDATE tbl_bin_group_versions"
                        MySQL = MySQL & " SET approved = 1, approved_by = 'TemplatePicker', approved_date = '" & Today & "'"
                        MySQL = MySQL & " WHERE bin_group_id = " & MyDataRow1("primary_bin_group_id")
                        MySQL = MySQL & " AND library_id = " & MyDataRow1("library_id")
                        MySQL = MySQL & " AND version_number = " & MyDataRow1("version_number")
                        MySQL = MySQL & " AND revision_number = " & mRevNum

                        MyCommandExec = New SqlCommand(MySQL, gDBCon)
                        MyCommandExec.ExecuteNonQuery()
                        'MyRSTExec.Open(MySQL, gDB, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
                    Else
                        varFromDisplay = "Playlist Server"
                        varFrom = "playlist@clubcom.com"
                        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                        varBCC = ""
                        varSubject = "Template Picker Failure"
                        varMessage = ""
                        varMessage = varMessage & "Template Picking has failed for the following:"
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Channel ID# " & pChannelID
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Revision # " & mRevNum
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & gPLServer

                        Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                        gLogFile.Flush()
                    End If
                End If
                MyDataset2.Dispose()
                MyAdaptor2.Dispose()
                'MyRST2.Close()
            End If 'End NeedToPick
            'MyRST1.MoveNext()
        Next MyDataRow1  'while not myRst1.eof
        MyDataset1.Dispose()
        MyAdaptor1.Dispose()
        'MyRST1.Close()

        varFromDisplay = "Playlist Server"
        varFrom = "playlist@clubcom.com"
        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
        varBCC = ""
        varSubject = "Template Picker Notification"
        varMessage = ""
        varMessage = varMessage & "Channel Templates have been picked for Channel ID# " & pChannelID
        varMessage = varMessage & vbCrLf
        varMessage = varMessage & vbCrLf
        varMessage = varMessage & gPLServer

        [b]Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)[/b]
        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Channel Templates have been picked for Channel ID# " & pChannelID)
        gLogFile.Flush()

        CType(fMainForm, frmPLUpload).pgBar.Value = 0
        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "RUNNING..."
        CType(fMainForm, frmPLUpload).Refresh()

        GoTo Template_Picker_EXIT

Template_Picker_ERROR:
        If File.Exists("C:\SERVER_ALIVE") = True Then
            Kill("C:\SERVER_ALIVE")
        End If
        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "ERROR: " & Err.Number & " - " & Err.Description)
        gLogFile.Flush()
        Call MsgBox("ERROR: " & Err.Number & " - " & Err.Description, MsgBoxStyle.Critical)
        Resume

Template_Picker_EXIT:

    End Sub

If I come into this procedure and break the code at the first line:
If pMaxVersionOnly = True Then
and then jump down to the call to send the email, then the email sends fine.
If the procedure runs normally and then calls the send mail procedure, then it hangs. Adn if I pause the execution, it is stuck on the line:
System.Web.Mail.SmtpMail.Send(email)
Adn it is highlighted in Green, indicating the call is processing.
I have let it sit for up to a half an hour and it never returns. When it does work, it returns instantly after calling the Send.
I went through an made sure I disposed of all the datasets and adaptors I was using (not that it should cause this problem). I'm kind of at a loss right now.

Any ideas are appreciated. Thanks. :)
 
More that got cut of...

Code:
                        varFrom = "playlist@clubcom.com"
                        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
                        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
                        varBCC = ""
                        varSubject = "Template Picker Failure"
                        varMessage = ""
                        varMessage = varMessage & "Template Picking has failed for the following:"
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Channel ID# " & pChannelID
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Library ID# " & MyDataRow1("library_id")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Version # " & MyDataRow1("version_number")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Revision # " & mRevNum
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & "Bin Group ID # " & MyDataRow1("primary_bin_group_id")
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & vbCrLf
                        varMessage = varMessage & gPLServer

                        Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
                        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Template picking failed for Channel ID# " & pChannelID & " Library ID# " & MyDataRow1("library_id") & " Version # " & MyDataRow1("version_number") & " Revision # " & mRevNum & " Bin Group ID # " & MyDataRow1("primary_bin_group_id"))
                        gLogFile.Flush()
                    End If
                End If
                MyDataset2.Dispose()
                MyAdaptor2.Dispose()
                'MyRST2.Close()
            End If 'End NeedToPick
            'MyRST1.MoveNext()
        Next MyDataRow1  'while not myRst1.eof
        MyDataset1.Dispose()
        MyAdaptor1.Dispose()
        'MyRST1.Close()

        varFromDisplay = "Playlist Server"
        varFrom = "playlist@clubcom.com"
        varTo = "brandonmurray@clubcom.com,aljones@clubcom.com"
        varCC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,victorwashy@clubcom.com"
        varBCC = ""
        varSubject = "Template Picker Notification"
        varMessage = ""
        varMessage = varMessage & "Channel Templates have been picked for Channel ID# " & pChannelID
        varMessage = varMessage & vbCrLf
        varMessage = varMessage & vbCrLf
        varMessage = varMessage & gPLServer

        [b]Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)[/b]
        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "Channel Templates have been picked for Channel ID# " & pChannelID)
        gLogFile.Flush()

        CType(fMainForm, frmPLUpload).pgBar.Value = 0
        CType(fMainForm, frmPLUpload).sbStatus.Panels(1).Text = "RUNNING..."
        CType(fMainForm, frmPLUpload).Refresh()

        GoTo Template_Picker_EXIT

Template_Picker_ERROR:
        If File.Exists("C:\SERVER_ALIVE") = True Then
            Kill("C:\SERVER_ALIVE")
        End If
        gLogFile.WriteLine(CStr(Now) & Chr(9) & "Template_Picker" & Chr(9) & "ERROR: " & Err.Number & " - " & Err.Description)
        gLogFile.Flush()
        Call MsgBox("ERROR: " & Err.Number & " - " & Err.Description, MsgBoxStyle.Critical)
        Resume

Template_Picker_EXIT:

    End Sub

If I come into this procedure and break the code at the first line:
If pMaxVersionOnly = True Then
and then jump down to the call to send the email, then the email sends fine.
If the procedure runs normally and then calls the send mail procedure, then it hangs. Adn if I pause the execution, it is stuck on the line:
System.Web.Mail.SmtpMail.Send(email)
Adn it is highlighted in Green, indicating the call is processing.
I have let it sit for up to a half an hour and it never returns. When it does work, it returns instantly after calling the Send.
I went through an made sure I disposed of all the datasets and adaptors I was using (not that it should cause this problem). I'm kind of at a loss right now.

Any ideas are appreciated. Thanks. :)
 
Look like I finally got it all!!
Must be a limit to the number of characters you can post! LOL!
Anyway, I duplicated the last line of each post in the first line of the next post.
If you copy it all out to paste into an editor so it is readable, you can cut out the extra lines.
And that "&n" at the end of the one post is not in my code. Nto sure what that is.

Thansk all. :)
 
a few things before we get to the important part

change things like these

varMessage = varMessage & vbCrLf

into

varMessage &= vbCrLf
or
varMessage &= controlchars.crlf
or
varMessage &= environment.newline
even better
varmessage.concat(...)
or use a stringbuilder

leave out the on error goto

leave out the call ...

use parameters instead of mysql = mysql & ...

now the important bit
I would redesign the smtpmailer class
where do you instantiate the smtpmailerclass in your class? I can't seem to find it.
do the other smtpmail thingies work??

here you have the new smtpmailer class.
I would add this to the templatepicker
dim objsmtpmailer as smtpmailer

and then replace this
Call SMTPMail.SendMail(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)

with this

objSMTPMailer = new smtpmailer(varFromDisplay, varFrom, varTo, varCC, varBCC, varSubject, varMessage)
objsmtpmailer.sendmail

or

dim objSMTPmailer as new smtpmailer

with this

objsmtpmailer.FromDisplay = "Playlist Server"
objsmtpmailer.From = "playlist@clubcom.com"
objsmtpmailer.Toadress = "brandonmurray@clubcom.com,aljones@clubcom.com"
objsmtpmailer.CC = "blakekercovich@clubcom.com,georgedumaine@clubcom.com,
victorwashy@clubcom.com"
objsmtpmailer.BCC = ""
objsmtpmailer.Subject = "Template Picker Notification"
objsmtpmailer.Message = varMessage & "Channel Templates have been picked for Channel ID# " & pChannelID & controlchars.crlf & controlchars.crlf & gPLServer
objsmtpmailer.sendmail

Code:
Option Strict Off
Option Explicit On 
Option Compare Text
Imports System
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Mail

Friend Class SMTPMailer
    Private strFromDisplay As String
    Private strFrom As String
    Private strTo As String
    Private strCC As String
    Private strBCC As String
    Private strSubject As String
    Private strMessage As String
    Private strReplyTo As String
    Private objEmail As New MailMessage

    Public Property FromDisplay() As String
        Get
            Return strFromDisplay
        End Get
        Set(ByVal Value As String)
            strFromDisplay = Value
        End Set
    End Property

    Public Property From() As String
        Get
            Return strFrom
        End Get
        Set(ByVal Value As String)
            strFrom = Value
        End Set
    End Property

    Public Property ToAdress() As String
        Get
            Return strTo
        End Get
        Set(ByVal Value As String)
            strTo = Value
            strTo.Replace(",", ";")
        End Set
    End Property

    Public Property CC() As String
        Get
            Return strCC
        End Get
        Set(ByVal Value As String)
            strCC = Value
            strCC.Replace(",", ";")
        End Set
    End Property

    Public Property BCC() As String
        Get
            Return strBCC
        End Get
        Set(ByVal Value As String)
            strBCC = Value
            strBCC.Replace(",", ";")
        End Set
    End Property

    Public Property Subject() As String
        Get
            Return strSubject
        End Get
        Set(ByVal Value As String)
            strSubject = Value
        End Set
    End Property

    Public Property Message() As String
        Get
            Return strMessage
        End Get
        Set(ByVal Value As String)
            strMessage = Value
        End Set
    End Property

    Public Property ReplyTo() As String
        Get
            Return strReplyTo
        End Get
        Set(ByVal Value As String)
            strReplyTo = Value
        End Set
    End Property

    Public Sub New()
        strFromDisplay = ""
        strFrom = ""
        strTo = ""
        strCC = ""
        strBCC = ""
        strSubject = ""
        strMessage = ""
        strReplyTo = ""
    End Sub

    Public Sub New(ByVal FromDisplay As String, ByVal From As String, ByVal ToAdress As String, ByVal CC As String, ByVal BCC As String, ByVal Subject As String, ByVal Message As String)
        strFromDisplay = FromDisplay
        strFrom = From
        strTo = ToAdress.Replace(",", ";")
        strCC = CC.Replace(",", ";")
        strBCC = BCC.Replace(",", ";")
        strSubject = Subject
        strMessage = Message
        strReplyTo = ""
    End Sub

    Public Sub New(ByVal FromDisplay As String, ByVal From As String, ByVal ToAdress As String, ByVal CC As String, ByVal BCC As String, ByVal Subject As String, ByVal Message As String, ByVal ReplyTo As String)
        strFromDisplay = FromDisplay
        strFrom = From
        strTo = ToAdress.Replace(",", ";")
        strCC = CC.Replace(",", ";")
        strBCC = BCC.Replace(",", ";")
        strSubject = Subject
        strMessage = Message
        strReplyTo = ReplyTo
    End Sub

    Public Sub SendMail()
        objEmail.From = """" & strFromDisplay & """" & "<" & strFrom & ">"
        If strReplyTo <> "" Then
            objEmail.Headers.Add("Reply-To", strReplyTo)
        End If
        System.Web.Mail.SmtpMail.SmtpServer = "192.168.1.35"
        Try
            System.Web.Mail.SmtpMail.Send(objEmail)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Class

And we could make it even better by creating a strongly typed collection for toadress, cc and bcc properties.

I think this is my longest post ever. Hope you enjoy.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Christiaan,
First off, thank you for putting so much effort into helping me. :)
I implemented the changes that you provided.
Unfortunately the mail still fails to send. But the good news is that instead of hanging in oblivion, it actually returns and error message! :)
When the following line executes:
System.Web.Mail.SmtpMail.Send(objEmail)
The Catch block traps the following error:
"Could not access CDO.Message object"
Not the most descriptive error, but it's something none the less.
The odd thing is that the mail attempts always fail now. Before I could send the mail if I skipped the block of code that did the Dataset handling.

I do have some more questions about your techniques on how you handle different things, as you have sparked my interest. But I will wait on that stuff until I can address the mail problem of sending the email.
If you have any thoughts on what may be causing this error, let me know.
In the meantime, I'm off to see if I can Google anything helpful about it. :)

Thanks again.
 
Christiaan,
I found a really good site with info about System.Web.Mail at They have a section about the "Could not access CDO.Message" error.
The first thing they suggest doing is finding the "Inner Exceptions":
I put the code in the Try/Catch block and trapped the Inner Exceptions.
The 2 execptions trapped are:
error1.jpg

and
error2.jpg


If you have any ideas about these, let me know.
In the meantime I'll be trying to figure out exactly what these mean. Thanks
 
could it be that you're smtp adress is wrong?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 

Typically this exception has to deal with the following line of code (or I should say ABSENCE of the following line of code):
SmtpMail.SmtpServer = "mail.your-domain.com"
By default, if SmtpMail.SmtpServer is not set, System.Web.Mail is supposed to use localhost as the default property. However, for some reason this doesn't appear work. If you are using the local SMTP Service to send emails, you may try the following values:
"127.0.0.1"
"localhost"
"the_machine_name_here"
"the_real_dns_name_here"
"the_machine_IP_Address_here"

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
It worked yesterday with my old code when I would skip the Dataset part.
And it is still working with the VB6 project that is running live on all our servers.
 
I read that message about the default of localhost.
Since we are specifying a real SMTP server IP address, that shouldn't apply here.
Although I did try replacing the IP address with the localhost of 127.0.0.1 and it still got the same error.
I also tried a suggestion from that site of changing:
System.Web.Mail.SmtpMail.SmtpServer = "192.168.1.35"
to
System.Web.Mail.SmtpMail.SmtpServer.Insert(0, "192.168.1.35")
and that didn't work either.
 
To make sure there was not a problem with the server, I replaced your new SMTP code with my old code and then ran the project, skipping the Dataset operations, and it sent the email fine.
 
Well, here's an interesting test...
Leaving my old SMTP code in place, I stepped into the Template_Picker procedure and this time I executed the first opening of a Dataset, then I skipped down to the line where I dispose of the adaptor and set, and then call the email function. It sent the email fine.
So, it's not the fact that I am using a Dataset that is breaking the email.
But if I let the entire procedure run, then the email send just hangs.
I guess I'm going to have to run a little bit more of the code each time, until I find the point at which the email breaks and then go from there.
I'll let you know what I find...
 
Alright, I stepped through the code, going farther each time.
I have reached a point where I can replicate the error, but this makes no sense whatsoever!

Look for the For loop at the top of the Template_Picker code:
For mTemplateHour = 1 To 3
.....
Next mTemplateHour
CType(fMainForm, frmPLUpload).pgBar.Value = 0

If I put a breakpoint on the line "Next mTemplateHour" and then run the procedure. It will break after each of the 3 hours is finished. After the 3rd hour is finished, I jump the code down to the line that Disposes of Dataset1 and Adaptor1, right before the email.
Then call the email procedure and it sends fine.
Now, if I remove the breakpoint on the "Next mTemplateHour" line and set a breakpoint of the next line "CType(fMainForm, frmPLUpload).pgBar.Value = 0" and execute the procedure, then it will once again process all 3 hours (just without breaking in between each one). When the breakpoint stops, I do NOT execute the pgBar.Value, but simply jump down to the Dispose lines once again, and attempt to send the email.
This time the email send will hang on the Send line and not return.

This really makes no sense!
I have executed the EXACT same code. No additional lines were skipped or executed. The only difference is pausing to break the code between each hour and the hitting F5 to continue, or letting all 3 hours in the loop execute at once.
I can repeat this scenario over and over. Break between hours, and it sends fine. Execute continuously and it will hang.

I am truely lost now! If anyone has any suggestions, I would love to hear them.

Thanks
 
could you tell me the values of all the properties when it sends the mail and when not?

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Well, add to the weirdness...
I thought the only thing different between running the code straight through and breaking it between hours was the amount of time. So before the "Next mTemplateHour" line, I put a line to wait for 5 seconds "Sleep (5000)".
Ran it straight through and it sent the email fine.
Tested it several times and it works everytime.
Now believe me, I do NOT like this solution!
But until I figure out something better, it is working.

could you tell me the values of all the properties when it sends the mail and when not?
Are you referring to the properties passed to mail routine, like "To", "CC", etc.? If so, they are always the same when it would fail or if it would run.
 
Does anyone know of any other ways to send email through .Net that doesn't use the built-in System.Web.Mail
I was thinking I could try another mailing technique and see if that fixes the problem.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top