473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Retrying a Database Connection in a Loop using a Timer

I am new to vb.net and I am interested in attempting to connect to an SQL Server. I am pretty certain the answer I seek is found in System.Threading.Timer

I want to keep trying to connect a number of times before giving up and throwing an error.

Below is my code from inside my SQLDatabase class.
Before Connect is called, I have ensured the Connection string is set to the variable _Connection, and, that it is not already open
_Connection is a SQLConnection object

Private Sub Connect(ByVal MaxTries As Integer, ByVal Interval As Integer)
Dim ThisTry As Integer = 1
While ThisTry <= MaxTries
Try
_Connection.Open()
ThisTry = 0
Exit Sub
Catch ex As Exception
If ThisTry = MaxTries Then
Throw New Exception(ex.Message)
End If
Dim oCallback As New Threading.TimerCallback(AddressOf OnTimedEvent)
Dim oTimer As New System.Threading.Timer(oCallback)
oTimer.Change(0, Interval)
End Try
End While
End Sub
Private Sub OnTimedEvent(ByVal WhoIsThis As Object)

End Sub

What else to I need to do to make this work? Any suggestions would be greatly appreciated.

Thanks,
Steve
Apr 5 '08 #1
0 695

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lawrence | last post by:
Is there a way to tell PHP, "Spend 5 seconds trying to reach the database, if you can't reach it, then load the file from the cached flat file." I suspect the answer is no. I'm tempted to...
8
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the...
8
by: Dave Veeneman | last post by:
In a for-loop, is a calculated expression re-calculated on each pass through the loop, or only once, when the loop is initialized? For example, assume the following loop: for (int i = 0; i <...
15
by: Zeng | last post by:
Hi, The bigger my C# web-application gets, the more places I need to put in the tedious retrying block of code to make sure operations that can run into database deadlocks are re-run (retried)...
40
by: Jeff | last post by:
I have a system on a network and want to determine if anyone is currently connected to the back-end files. An interesting twist is that I have noticed that some users can be connected (have the...
3
by: bob | last post by:
In an effort to keep my UI responsive I have begun to run my time intensive methods on their own thread and in particular the database inserts. I open my DB connection in the constructor and close...
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
2
by: alxasa | last post by:
Hi, I have a setInterval which executes its command every 10 seconds in a infinite loop. I've got something real basic like: var processes=0; function startme(){ if(stopthisloop>1)
8
by: Ian | last post by:
I have an Access 2000 database that checks once every 4 seconds to see if a text file exists, if it does then it opens the text file, reads an ID, opens a report based on that ID, then deletes the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.