Solved

VB.net Timer Object to see if connection working

Posted on 2011-09-15
2
319 Views
Last Modified: 2012-06-27
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
Comment
Question by:murbro
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:murbro
Comment Utility
Thanks very much for the advice
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now