If the User Can Manage Data Sources configuration setting is True, the user can select which DSNs installed on their system they want to access in Stonefield Query. Often, DSN names are obscure names like PROD01 rather than meaningful names such as "Production Database" or the name of a company. Rather than displaying the DSN name in the Login and Open Database dialogs, you may wish to display a more descriptive name.

The DataEngine.GetDataSourceDescription script allows you to specify the descriptive name for a specific DSN. This script is called from the Manage Databases and Setup dialogs after the user successfully tests a DSN, and the return value of the script is saved in the DSN table in the Data subdirectory of the Stonefield Query program folder. The code you enter for this script can look up the descriptive name somewhere. For example, perhaps a company name is stored in one of the tables in the database. Your code could execute a SQL statement to obtain that company name.

Parameters
A reference to the Stonefield Query Application object, a reference to the Database object for the main database, and the name of the DSN.

Return Value
The descriptive name for the DSN or a blank string if no name can be found.

Example
Here's an example that retrieves the CONAME field from the CSCOM table in the database accessed by the specified DSN.

Visual FoxPro

lparameters toApplication as SQApplication, toDatabase as Database, tcDataSource
local lcReturn
toDatabase.ExecuteSQLStatement('select CONAME from CSCOM', , 'CSCOM')
lcReturn = trim(CONAME)
use
return lcReturn

VBScript

function Main(Application, Database, DataSource)
dim XMLDOM
Results = Database.ExecuteSQLStatement("select CONAME from CSCOM")
set XMLDOM = createobject("MSXML.DOMDocument")
XMLDOM.ASync = False
XMLDOM.LoadXML(Results)
Main = XMLDOM.selectSingleNode("/DataSet/_resultset/coname").Text
end function

JavaScript

function Main(Application, Database, DataSource) {
var Results, XMLDOM, Descrip ;
Results = Database.ExecuteSQLStatement('select CONAME from CSCOM') ;
XMLDOM = new ActiveXObject('MSXML.DOMDocument') ;
XMLDOM.ASync = false ;
XMLDOM.LoadXML(Results) ;
Descrip = XMLDOM.selectSingleNode('/DataSet/_resultset/coname').Text ;
return Descrip ;
}

C#

Please note that the method in this script must be named DataEngine_GetDataSourceDescription.

public static string DataEngine_GetDataSourceDescription(SFQApplication sfqApplication,
  Database database, string dataSource)
{	
  string description = String.Empty;
  string selectStmt = "select CONAME from CSCOM";
  string resultSet = database.ExecuteSQLStatement(selectStmt);
  XmlDocument doc = new XmlDocument();
  doc.LoadXml(resultSet);
  XmlNode node = doc.SelectSingleNode("/DataSet/_resultset/@coname");

  if (node != null)
  {
    description = node.Value;
  }
    
  return description;
}

VB.NET

Please note that the method in this script must be named DataEngine_GetDataSourceDescription.

public shared function DataEngine_GetDataSourceDescription(sfqApplication as SFQApplication,
  database as Database, dataSource as string) as string

  Dim description As String = String.Empty
  Dim selectStmt As String = "select CONAME from CSCOM"
  Dim resultSet As String = database.ExecuteSQLStatement(selectStmt)
  Dim doc As XmlDocument = new XmlDocument()
  doc.LoadXml(resultSet)
  Dim node As XmlNode = doc.SelectSingleNode("/DataSet/_resultset/@coname")

  If (Not node Is Nothing) Then
    description = node.Value
  End If
    
  return description
End Function

See also

Scripts