How to test that a connection is valid...


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I have a method that checks that a DataSource is valid by attempting to connect to it. However, when using ES, the method fails. I've tried two methods, both work if I'm setting a sql data source and both fail if I use ES.



Method 1

This method gets a DbConnection from the DataSource using the CreateBlankDbConnection method, then attempt to open it:

Private Function ValidateConnection(ByVal key As String) As Boolean

'-- Establish return var

Dim connOK As Boolean

'-- Validate the connection

Using testConn As Data.Common.DbConnection = DataBasics.DataSources(key).CreateBlankDbConnection

Try

testConn.Open()

connOK = True

Catch ex As Exception

'-- Connection failed

connOK = False

End Try

End Using

'-- Return result

Return connOK

End Function




Method 2

This method attempts to use a BO (typically one that has little data in the underlying table) to attempt to fill it. The idea here is that if the fill method works (no exceptions) then the connection is valid:

Private Function ValidateAppDbConnection() As Boolean

'-- Establish return var

Dim connOK As Boolean

'-- Try to fill a BO. If there is no exception we have a connection.

Try

Using bo As New MyBO()

bo.FillByPrimaryKey(1)

End Using

connOK = True

Catch ex As Exception

connOK = False

End Try

'-- return results

Return True 'connOK

End Function




I'm calling these in the SetDataSources event handler. Again these both work when not using ES.



So, I'm wondering why they don't work and then I'm wondering how I'd check the connection when connecting to the data via ES.



Thanks!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search