﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » How to test that a connection is valid...</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 10:38:59 GMT</lastBuildDate><ttl>20</ttl><item><title>How to test that a connection is valid...</title><link>http://forum.strataframe.net/FindPost12401.aspx</link><description>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.&lt;br&gt;
&lt;br&gt;
[b]Method 1[/b]&lt;br&gt;
This method gets a DbConnection from the DataSource using the CreateBlankDbConnection method, then attempt to open it:&lt;br&gt;
[codesnippet]  Private Function ValidateConnection(ByVal key As String) As Boolean&lt;br&gt;
    '-- Establish return var&lt;br&gt;
    Dim connOK As Boolean&lt;br&gt;
    '-- Validate the connection&lt;br&gt;
    Using testConn As Data.Common.DbConnection = DataBasics.DataSources(key).CreateBlankDbConnection&lt;br&gt;
      Try&lt;br&gt;
        testConn.Open()&lt;br&gt;
        connOK = True&lt;br&gt;
      Catch ex As Exception&lt;br&gt;
        '-- Connection failed&lt;br&gt;
        connOK = False&lt;br&gt;
      End Try&lt;br&gt;
    End Using&lt;br&gt;
    '-- Return result&lt;br&gt;
    Return connOK&lt;br&gt;
  End Function[/codesnippet]&lt;br&gt;
&lt;br&gt;
[b]Method 2[/b]&lt;br&gt;
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:&lt;br&gt;
[codesnippet]    Private Function ValidateAppDbConnection() As Boolean&lt;br&gt;
    '-- Establish return var&lt;br&gt;
    Dim connOK As Boolean&lt;br&gt;
    '-- Try to fill a BO. If there is no exception we have a connection.&lt;br&gt;
    Try&lt;br&gt;
      Using bo As New MyBO()&lt;br&gt;
        bo.FillByPrimaryKey(1)&lt;br&gt;
      End Using&lt;br&gt;
      connOK = True&lt;br&gt;
    Catch ex As Exception&lt;br&gt;
      connOK = False&lt;br&gt;
    End Try&lt;br&gt;
    '-- return results&lt;br&gt;
    Return True 'connOK&lt;br&gt;
  End Function[/codesnippet]&lt;br&gt;
&lt;br&gt;
I'm calling these in the SetDataSources event handler. Again these both work when [b]not[/b] using ES.  &lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Thanks!</description><pubDate>Tue, 06 Nov 2007 09:09:38 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: How to test that a connection is valid...</title><link>http://forum.strataframe.net/FindPost12480.aspx</link><description>The first one won't work because it's trying to use the SqlConnection object directly... &lt;/P&gt;&lt;P&gt;However, the second one should work fine... what's the exception that you're getting on the second one when you're using an ES data source?</description><pubDate>Tue, 06 Nov 2007 09:09:38 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: How to test that a connection is valid...</title><link>http://forum.strataframe.net/FindPost12459.aspx</link><description>bump... :blink:</description><pubDate>Mon, 05 Nov 2007 14:46:13 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>