I have a script that runs to send email's to a list of users in a database. To get the data, it actually makes several querys. I keep getting errors about the connection being already open, or not open, etc. Below is the code I am using now and the last error I have gotten. How can I clean this up and make sure it has a open connection when needed but not open and closing everytime and using too many resources.
If daily = "False" Then
Dim strConn, strSQL As String
strConn = ConfigurationManager.ConnectionStrings("EmailConnection").ToString
strSQL = "SELECT name, email, basicday FROM email WHERE test='true'"
Dim da As New SqlDataAdapter(strSQL, strConn)
Dim emaillist As New DataSet
If Not emaillist.Tables.Count = 0 Then
Dim sql As String
For Each dr As DataRow In emaillist.Tables(0).Rows
Basicday = CType(dr("basicday"), Integer)
mySqlCommand = New SqlCommand("S
View Complete Post