Click here to Skip to main content
15,917,473 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Windows Services Problem? Pin
mythinky27-Jun-04 15:24
mythinky27-Jun-04 15:24 
GeneralRe: Windows Services Problem? Pin
Dave Kreskowiak27-Jun-04 18:13
mveDave Kreskowiak27-Jun-04 18:13 
GeneralRe: Windows Services Problem? Pin
Anonymous27-Jun-04 23:36
Anonymous27-Jun-04 23:36 
GeneralRe: Windows Services Problem? Pin
Dave Kreskowiak28-Jun-04 0:41
mveDave Kreskowiak28-Jun-04 0:41 
GeneralRe: Windows Services Problem? Pin
mythinky28-Jun-04 15:49
mythinky28-Jun-04 15:49 
GeneralRe: Windows Services Problem? Pin
Dave Kreskowiak28-Jun-04 16:48
mveDave Kreskowiak28-Jun-04 16:48 
QuestionEmail in Windows Service? Pin
mythinky24-Jun-04 18:05
mythinky24-Jun-04 18:05 
AnswerRe: Email in Windows Service? Pin
Dave Kreskowiak25-Jun-04 3:36
mveDave Kreskowiak25-Jun-04 3:36 
It looks like you only running this code once a day. This is not a good candidate for a service. This should have been written as a normal Windows app and run as a Scheduled Task. This will prevent your app from consuming system resources all day and not doing anything with them.

Anyway...

There are lots of problems with your code, but I'll just cover a few for now...

mythinky wrote:
Public Shared Function InternetGetConnectedState(ByRef description As Integer, ByVal reservedValue As Integer) As Boolean
End Function

Public Shared Function IsConnectedToInternet() As Boolean
Dim desc As Integer
Return InternetGetConnectedState(desc, 0)
End Function

This will always return False because your InternetGetConnectedState function doesn't have any code in it.

Drop your CheckConnection code. You don't need it. Instead rewrite it as GetDatabaseConnection. This function should accept the Server, DBLib, Username and Password as parameters, build its own connection string, then try and get a connection to the database. If the connection succeeds, return the SqlConnection object, else do nothing. The Exception will pop up the call stack and get handled in the Elapsed Try/Catch block.

Opening a connection and keeping it open for the duration of your app is a really bad idea. This will keep an expensive licensed connection open on the SQL server not release it. You should get a connection to the server as late as possible and release it as early as possible in your code. Don't hog server resources by keeping a connection open.

You have two timers in your app, only one of which you are using. Remove all Timer code and references.

Don't start your timers until all of your initalization is done. This means don't put Timer1.Enable at the start of your OnStart code, put it at the end.

Also, in your OnStart code, forget checking your database connection. You don't need it. When your Timer Elapsed code runs, your sequence should be something like this:
Disable the Timer.  (Yes, you heard me right!)
Check to see if it's time to go to work
    If not, Exit Sub
Get the app settings.
Try
    Get a connection to the database, passing the settings we got.
    Get the information we need from the SQL Server.
    Do we need to do anything with the data.
        No, report this to the EventLog.
    Else
        Try
            Do our processing on the EMail message.
            Report to the EventLog what we did.
        End Try
    End If
Catch
    Report any errors to the Event Log.
Finally
    Make sure our connection object is closed and disposed.
End Try
Re-enable the Timer.

Why is the timer being disabled at the beginning of the Elapsed event code? Because this will prevent the Timer from firing another Elapsed event in case we're still in the middle of handling the last Elapsed event. When were done handling the event, re-enable the timer.


RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

GeneralRe: Email in Windows Service? Pin
mythinky27-Jun-04 15:37
mythinky27-Jun-04 15:37 
GeneralRe: Email in Windows Service? Pin
mythinky27-Jun-04 15:49
mythinky27-Jun-04 15:49 
GeneralRe: Email in Windows Service? Pin
Dave Kreskowiak27-Jun-04 18:29
mveDave Kreskowiak27-Jun-04 18:29 
GeneralRe: Email in Windows Service? Pin
Dave Kreskowiak27-Jun-04 18:21
mveDave Kreskowiak27-Jun-04 18:21 
GeneralSave As Type Pin
Esther C24-Jun-04 17:29
Esther C24-Jun-04 17:29 
GeneralRe: Save As Type Pin
Esther C24-Jun-04 17:41
Esther C24-Jun-04 17:41 
GeneralRe: Save As Type Pin
Dave Kreskowiak25-Jun-04 3:00
mveDave Kreskowiak25-Jun-04 3:00 
Generalsystem tray Pin
Anonymous24-Jun-04 16:14
Anonymous24-Jun-04 16:14 
GeneralRe: system tray Pin
Dave Kreskowiak25-Jun-04 2:42
mveDave Kreskowiak25-Jun-04 2:42 
QuestionHow to Select Root in TreeView? Pin
vancouver77724-Jun-04 12:44
vancouver77724-Jun-04 12:44 
AnswerRe: How to Select Root in TreeView? Pin
Dave Kreskowiak25-Jun-04 4:23
mveDave Kreskowiak25-Jun-04 4:23 
GeneralRe: How to Select Root in TreeView? Pin
vancouver77725-Jun-04 6:28
vancouver77725-Jun-04 6:28 
GeneralRe: How to Select Root in TreeView? Pin
Dave Kreskowiak25-Jun-04 7:17
mveDave Kreskowiak25-Jun-04 7:17 
AnswerRe: How to Select Root in TreeView? Pin
Ravi S.V.29-Jun-04 1:03
Ravi S.V.29-Jun-04 1:03 
General. Pin
hssaroch24-Jun-04 1:09
hssaroch24-Jun-04 1:09 
GeneralRe: Reading XL files in VB6 Pin
RichardGrimmer24-Jun-04 6:11
RichardGrimmer24-Jun-04 6:11 
GeneralTrace the information about share sessions Pin
Mekong River23-Jun-04 23:03
Mekong River23-Jun-04 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.