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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Service can anyone tellme why this routine fails?

Status
Not open for further replies.

majordog

Programmer
Jul 8, 2002
222
CA
Private Function AnyEmailsToSend(ByVal command As String) As Boolean
Dim ds As New DataSet
Dim MyConnection As SqlConnection = New SqlConnection(DatabaseKey)
Dim MyDataAdapter As SqlDataAdapter = New SqlDataAdapter(command, MyConnection)
Dim MyDataTable As New DataTable
Dim MyDataRow As DataRow
Dim intNumber As Integer

EventLog1.WriteEntry("Inside AnyEmailsToSend")
Try
MyDataAdapter.Fill(ds, "Count")
MyDataTable = ds.Tables(0)
MyConnection.Close()
Catch
EventLog1.WriteEntry("Nope")
End Try

Try
For Each MyDataRow In MyDataTable.Rows
intNumber = MyDataRow("Number")
Next
Catch
EventLog1.WriteEntry("Error occurred in counting mail to send. Number was: '" & intNumber & "' ")
End Try
'MyConnection.Close()
EventLog1.WriteEntry(" '" & intNumber & "' ")
If intNumber > 0 Then
AnyEmailsToSend = True
Else
AnyEmailsToSend = False
End If
End Function
 
Sorry I should also mention that the Select statement passed in is correct and does indeed return values and that it fails on the first TRY CATCH.
 
The SqlDataAdapter implicitly opens the connection. The database permissions were not correct. Correcting thatsolved the problem. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top