Monday, July 13, 2009

Tip #46 – Getting Server Information from an AdsConnection Object

The AdsConnection object in the Advantage .NET Data Provider has many properties which provide information about the server it is connected to. With an active connection you can get the following information: Server Name, Server Type, Server Version, Server Time, Connection Handle, Connection Timeout and Date Format.

These properties can be easily accessed once the connection is opened and used within your application. For example you may wish to have your application verify that a specific version of Advantage is running you could do this with the following code.

   1: // Build the connection string
   2: string sConn = "Data Source=C:\data;ServerType=Remote";
   3:  
   4: // Connect to Advantage
   5: AdsConnection cnADS = new AdsConnection( sConn );
   6: cnAds.Open();
   7:  
   8: // Compare the server version
   9: string sVersion = "9.10.0.9";
  10: if ( sVersion.CompareTo(cnAds.ServerVersion) != 0 )
  11:   MessageBox.Show( "You must have Advantage version " + sVersion, "Invalid Version");

There is a sample application posted on CodeCentral which demonstrates retrieving all of the server properties through the AdsConnection object. The server information is shown below:

Server Information

No comments: