Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

VB.net Timer Object to see if connection working

Hi

In VB.net I connect to a SQL database using the following code.
I want to use a timer object and code to test if the connection works.
How would I do this? What code would I use?
Public Sub oAppend(ByVal oDate As Date, ByVal oText As String, ByVal oNumber As Single)
 
    Dim oSQL As String
    
    On Error GoTo EH
    
    Set con = New ADODB.Connection
    
    con.Open "Provider=SQLOLEDB;Data Source=196.11.247,1884;Network Library=DBMSSOCN;Initial Catalog=test;User ID=llllk3;Password=4lllgg;"

    Set cmd = New ADODB.Command

Open in new window

0
Murray Brown
Asked:
Murray Brown
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
If you are starting your project, I would not start with ADODB. This technology is there mainly to support old types of applications.

This is particularly true when you use SQL Server, since .NET has a library specifically dedicated to SQL Server. Except for connections and commands, you would have to learn a new way of working with databases, but this is the .NET way and the way to work with web applications as well as Windows application. For instance, the Recordset does not exist anymore in that library, and you do not have a permanent connection to the database.

Working with the System.Data.SqlClient library instead of ADODB will provide you not only with a sensible gain in performance, but also with a lot of extra useful features.

As an example, the SqlConnection object has a timeout feature built-in. After a fixed delay, you receive an exception if the application was not able to connect in a timely fashion. No need for a timer, it is there by default.

And before you ask, no, I do not have a good book or web site to recommend to learn how to use the .NET libraries (ADODB is a not a .NET library, it is a bridge to an old COM library). Everybody has his own way of learning new things. Books get outdated to fast to be really useful, and I could suggest you a web site that is excellent for me, but would not be to a level or have a content in accord with your level of expertise and you past experience.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for the advice
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now