Previous Topic: SQL AdaptersNext Topic: SQL Adapter Connection String


SQL Adapter Configuration File Example

Given an MS Access (.mdb) database with the following table:

SQL Adapter Configuration Example

The only difference in the configuration file in a SQL Adapter configuration file and the file Adapter configuration file is the DatasourceInterface section.

The DatasourceInterface section in a file Adapter stores the Files collection, where the SQL Adapter file has the ConnectionString and QueryCollection.

The main difference between the two configuration files is in the retrieval and parsing method. The rest of the file is the same.

The SQL interface defines the connection to the database and the queries used to retrieve the data.

Details are as follows:

Note: The section is defined based on the above data source database.

Connection string element

ConnectionString: Connection string for accessing the source DataBase.

The ConnectionString can be defined in the DataSourceInterface element and/or in the Query elements. The ConnectionString definition in the DataSourceInterface element is the default and is used only in a query without a ConnectionString definition. This allows the Adapter to connect to several databases where each query can have its own connection string. For more details on the connection string mechanism, refer to the following section.

Configuration File Query Collection Section

Query: Specifies the query attributes.

Following is a complete configuration file in XML layout:

<?xml version="1.0" encoding="utf-8"?>
<AdapterConfiguration>
  <General MajorVersion="3" MinorVersion="0" RunOnce="yes" LogDebugMode="yes" ConsoleDebugMode="yes" WorkingDirectoryName="d:\Oblicore\Training Kit\Exercises\Adapters\SQL Adapters\Ex1\Solution">
      <DataSourceDifferenceFromUTC DefaultOffset="1" TimeFormat="%Y/%m/%d-%H:%M:%S"/>
   </General>
   <OblicoreInterface Mode="online">
      <OnlineInterface Port="2000" SecurityLevel="none"/>
   </OblicoreInterface>
   <DataSourceInterface>
      <ConnectionString>

          Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\Oblicore\Training Kit\Exercises\Adapters\SQL Adapters\Ex1\db1.mdb;

      </ConnectionString>
      <QueryCollection>
         <Query QueryName="Query" InputFormat="InputFormat" SleepTime="5">
            <SelectStatement AutoCompleteQuery="yes">

               select time,server,availability from t_availability

          </SelectStatement>
            <QueryKeyFields>
               <KeyField Name="time" Sort="asc" ValueLeftWrapper="#" ValueRightWrapper="#"/>
               <KeyField Name="server" Sort="asc"/>
               <SelectInitialValues>

                     select 'AAA','1/1/1970'

               </SelectInitialValues>
            </QueryKeyFields>
         </Query>
      </QueryCollection>
   </DataSourceInterface>
   <InputFormatCollection>
      <InputFormat InputFormatName="InputFormat">
         <InputFormatFields>
            <InputFormatField Name="timestamp" Type="time" TimeFormat="%m/%d/%Y %I:%M:%S %p"/>
            <InputFormatField Name="server" Type="string"/>
            <InputFormatField Name="status" Type="integer"/>
         </InputFormatFields>
         <TranslatorSwitch DefaultTranslator="Translator"/>
      </InputFormat>
   </InputFormatCollection>
   <TranslatorCollection>
      <Translator TranslatorName="Translator">
         <TranslatorFields>
            <TranslatorField Name="ResourceId" SourceType="table" SourceName="ResourceTable"/>
            <TranslatorField Name="EventTypeId" SourceType="constant" ConstantValue="1500"/>
            <TranslatorField Name="Timestamp" SourceType="field" SourceName="timestamp"/>
            <TranslatorField Name="Value" SourceType="field" SourceName="status"/>
         </TranslatorFields>
      </Translator>
   </TranslatorCollection>
   <TranslationTableCollection LoadingMode="remote">
      <TranslationTable Name="ResourceTable" DestinationType="resource">
         <TranslationField>server</TranslationField>
      </TranslationTable>
   </TranslationTableCollection>
</AdapterConfiguration>