Print Page | Close Window

Checking Connection to a Web Database

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1319
Printed Date: 04-Jun-2024 at 11:29am


Topic: Checking Connection to a Web Database
Posted By: *Calsy
Subject: Checking Connection to a Web Database
Date Posted: 14-Jun-2009 at 8:17pm
Hi All,
During the load of our application we need to check if the user can access an SQL DB via the web and set a system boolean which we will then refer to. We use the following code:

 Dim x As IdeaBlade.Util.IdeaBladeConfig = IdeaBlade.Util.IdeaBladeConfig.Instance
            x.RdbKeys(1).Connection = "SQLConnectionGoesHERE"

            BO.SystemProperties.PMWebConnection = New PersistenceManager(True, "Key")

            If BO.SystemProperties.PMWebConnection.CheckDataSourceKey("Key") = DataSourceKeyStatus.UnableToConnect Then
                BO.SystemProperties.IsUserPortalConnected = False
            Else
                BO.SystemProperties.IsUserPortalConnected = True
            End If

This does work however when the CheckDataSourceKey section runs and there is no internet connection available it can take up to 15 seconds until it moves to the next line.

Is there a better(quicker) way to do this or is there a safe way I can multi-thread the database connection check as this is just too long for the user to wait.

Thanks



Replies:
Posted By: kimj
Date Posted: 15-Jun-2009 at 10:04am
CheckDataSourceKey, in order to validate the connection information, will open up a test connection to the DB.  If all you need is to determine if the server hosting the DB is available, then PingServer(url) in IdeaBlade.Util.HttpFns might help.  Note that ping will take the URL for the server, so you'll have to build it up from information in the connection string.
 
You can multi-thread the PingServer call without potential problems.  CheckDataSourceKey is probably safe to use multi-threaded, but it would still be a better idea to make that call from another PM when using a separate thread.
 
You don't need to use DevForce to check the internet connection - the System.Net.NetworkInformation namespace contains some useful classes, such as Ping or NetworkInterface, which may do what you need.



Print Page | Close Window