Configuration File Help

Thread is closed for posting
5 posts, 0 answers
  1. Joebet
    Joebet avatar
    23 posts
    Member since:
    Jun 2010

    Posted 28 Jul 2010 Link to this post

    Good day. may I know if i can separate the connectionstring configuration with the telerik database mapping? below is my sample configuration setting. 


    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="openaccess" type="Telerik.OpenAccess.Config.ConfigSectionHandler, Telerik.OpenAccess.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" requirePermission="false" />
      </configSections>
      <connectionStrings>
        <add name="SentientConnection" connectionString="data source=INTJLMUTIA\SQLSVR2008;initial catalog=Sentient.Data.Core;integrated security=True" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references />
        <connections>
          <connection id="SentientConnection2">
            <databasename>Sentient.Data.Core</databasename>
            <servername>intprmunar\sql08</servername>
            <integratedSecurity>False</integratedSecurity>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
            <user>pmunar</user>
            <password>pmunar</password>
          </connection>
          <connection id="SentientConnection">
            <connectionString>Data Source=INTJLMUTIA\SQLSVR2008;Initial Catalog=Sentient.Data.Core;Integrated Security=True</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
          <mapping id="mssqlMapping">
            <namespace name="Sentient.Business.Entity.Core">
              <class name="Customer">
                <extension key="db-table-name" value="Customer" />
                <extension key="db-key-generator" value="AUTOINC" />
                <field name="id">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ID" />
                  </extension>
                </field>
                <field name="address">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Address" />
                  </extension>
                </field>
                <field name="birthDate">
                  <extension key="db-column">
                    <extension key="db-column-name" value="BirthDate" />
                  </extension>
                </field>
                <field name="city">
                  <extension key="db-column">
                    <extension key="db-column-name" value="City" />
                  </extension>
                </field>
                <field name="contactName">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ContactName" />
                  </extension>
                </field>
                <field name="country">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Country" />
                  </extension>
                </field>
                <field name="customerCode">
                  <extension key="db-column">
                    <extension key="db-column-name" value="CustomerCode" />
                  </extension>
                </field>
                <field name="customerName">
                  <extension key="db-column">
                    <extension key="db-column-name" value="CustomerName" />
                  </extension>
                </field>
                <field name="email">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Email" />
                  </extension>
                </field>
                <field name="fax">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Fax" />
                  </extension>
                </field>
                <field name="isActive">
                  <extension key="db-column">
                    <extension key="db-column-name" value="IsActive" />
                  </extension>
                </field>
                <field name="telephone">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Telephone" />
                  </extension>
                </field>
                <field name="version">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Version" />
                  </extension>
                </field>
              </class>
              <class name="Product">
                <extension key="db-key-generator" value="AUTOINC" />
                <extension key="db-table-name" value="Product" />
                <field name="id">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ID" />
                  </extension>
                </field>
                <field name="description">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Description" />
                  </extension>
                </field>
                <field name="isActive">
                  <extension key="db-column">
                    <extension key="db-column-name" value="IsActive" />
                  </extension>
                </field>
                <field name="price">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Price" />
                  </extension>
                </field>
                <field name="productCode">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ProductCode" />
                  </extension>
                </field>
                <field name="productName">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ProductName" />
                  </extension>
                </field>
                <field name="qty">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Qty" />
                  </extension>
                </field>
                <field name="version">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Version" />
                  </extension>
                </field>
              </class>
            </namespace>
          </mapping>
        </mappings>
      </openaccess>
    </configuration>

    My task is simply migrating the BackendConfigurations node and the mapping node in the above app.config file to a separate file.. the reason for doing this is to have a separate config file for connectionstrings only and a config file for the entity map. pls i really needed this help. tnx
  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 28 Jul 2010 Link to this post

    Hello Joebet,
    Yes you can. There is a special Database.Get method that takes an XmlElement, where you are getting it from is your part, you can construct it during runtime or just read it from a file. Please have a look into the example here:

    http://www.telerik.com/help/openaccess-orm/telerik.openaccess-telerik.openaccess.database-get(string,xmlelement).html

    Best wishes,
    Jan Blessenohl
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Joebet
    Joebet avatar
    23 posts
    Member since:
    Jun 2010

    Posted 28 Jul 2010 Link to this post

    Hi Jan, thanks for the swift reply. And thanks for the reference you had provided. But still it is unclear for me how to do what I want to accomplish  as stated above. what you are proposing is that i will make a separate project or another app.config file by which the database.get will extract the connectionstring out of the file? so that means in my previous app.config file I will delete the connection string and reference the dll that contains the connectionstring? my idea are as follows:

    first app.config

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="openaccess" type="Telerik.OpenAccess.Config.ConfigSectionHandler, Telerik.OpenAccess.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" requirePermission="false" />
      </configSections>
      <connectionStrings>
      </connectionStrings>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references>
          <reference assemblyname="Sentient.Connectivity.Core" configrequired="True" />
        </references>
        <connections>
          
        </connections>
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
          <mapping id="mssqlMapping">
            <namespace name="Sentient.Business.Entity.Core">
              <class name="Customer">
                <extension key="db-table-name" value="Customer" />
                <extension key="db-key-generator" value="AUTOINC" />
                <field name="id">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ID" />
                  </extension>
                </field>
                <field name="address">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Address" />
                  </extension>
                </field>
                <field name="birthDate">
                  <extension key="db-column">
                    <extension key="db-column-name" value="BirthDate" />
                  </extension>
                </field>
                <field name="city">
                  <extension key="db-column">
                    <extension key="db-column-name" value="City" />
                  </extension>
                </field>
                <field name="contactName">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ContactName" />
                  </extension>
                </field>
                <field name="country">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Country" />
                  </extension>
                </field>
                <field name="customerCode">
                  <extension key="db-column">
                    <extension key="db-column-name" value="CustomerCode" />
                  </extension>
                </field>
                <field name="customerName">
                  <extension key="db-column">
                    <extension key="db-column-name" value="CustomerName" />
                  </extension>
                </field>
                <field name="email">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Email" />
                  </extension>
                </field>
                <field name="fax">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Fax" />
                  </extension>
                </field>
                <field name="isActive">
                  <extension key="db-column">
                    <extension key="db-column-name" value="IsActive" />
                  </extension>
                </field>
                <field name="telephone">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Telephone" />
                  </extension>
                </field>
                <field name="version">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Version" />
                  </extension>
                </field>
              </class>
              <class name="Product">
                <extension key="db-key-generator" value="AUTOINC" />
                <extension key="db-table-name" value="Product" />
                <field name="id">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ID" />
                  </extension>
                </field>
                <field name="description">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Description" />
                  </extension>
                </field>
                <field name="isActive">
                  <extension key="db-column">
                    <extension key="db-column-name" value="IsActive" />
                  </extension>
                </field>
                <field name="price">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Price" />
                  </extension>
                </field>
                <field name="productCode">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ProductCode" />
                  </extension>
                </field>
                <field name="productName">
                  <extension key="db-column">
                    <extension key="db-column-name" value="ProductName" />
                  </extension>
                </field>
                <field name="qty">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Qty" />
                  </extension>
                </field>
                <field name="version">
                  <extension key="db-column">
                    <extension key="db-column-name" value="Version" />
                  </extension>
                </field>
              </class>
            </namespace>
          </mapping>
        </mappings>
      </openaccess>
    </configuration>

    The second app.config that contains the connectionstring or the Sentient.Connectivity.Core 
    that was referenced by the first app.config.
    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="openaccess" type="Telerik.OpenAccess.Config.ConfigSectionHandler, Telerik.OpenAccess.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" requirePermission="false" />
      </configSections>
      <connectionStrings>
        <add name="SentientConnection" connectionString="data source=INTJLMUTIA\SQLSVR2008;initial catalog=Sentient.Data.Core;integrated security=True" providerName="System.Data.SqlClient" />
      </connectionStrings>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references />
        <connections>
          <connection id="SentientConnection">
            <connectionString>Data Source=INTJLMUTIA\SQLSVR2008;Initial Catalog=Sentient.Data.Core;Integrated Security=True</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
          <mapping id="mssqlMapping" />
        </mappings>
      </openaccess>
    </configuration>

    what bothered my is how can i make the first app.config to read the connectionstring of the second app.config? can you give me a sample project instead? thanks.. 





  4. Joebet
    Joebet avatar
    23 posts
    Member since:
    Jun 2010

    Posted 28 Jul 2010 Link to this post

    Hi found this thread (http://www.telerik.com/community/forums/orm/feature-requests/connection-strings-in-separate-file.aspx) that gives me an idea on how to accomplish  my task. below are the codes i had made.

    First app.config

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="openaccess" type="Telerik.OpenAccess.Config.ConfigSectionHandler, Telerik.OpenAccess.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342" requirePermission="false" />
      </configSections>
      <connectionStrings>
      </connectionStrings>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references />
        <connections configSource="AppConnection.Config"/>
         
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
          <mapping id="mssqlMapping">
            <namespace name="Connectivity">
              <class name="Product">
                <extension key="db-do-not-create-table" value="true" />
                <extension key="db-table-name" value="Product" />
                <field name="id" null-value="exception">
                  <extension key="db-column">
                    <extension key="db-type" value="INTEGER" />
                    <extension key="db-column-name" value="ID" />
                  </extension>
                </field>
                <field name="description">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="Description" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="isActive">
                  <extension key="db-column">
                    <extension key="db-type" value="TINYINT" />
                    <extension key="db-column-name" value="IsActive" />
                  </extension>
                </field>
                <field name="price">
                  <extension key="db-column">
                    <extension key="db-type" value="NUMERIC" />
                    <extension key="db-column-name" value="Price" />
                    <extension key="db-length" value="20" />
                    <extension key="db-scale" value="10" />
                  </extension>
                </field>
                <field name="productCode">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="ProductCode" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="productName">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="ProductName" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="qty">
                  <extension key="db-column">
                    <extension key="db-type" value="INTEGER" />
                    <extension key="db-column-name" value="Qty" />
                  </extension>
                </field>
                <field name="version2" null-value="exception">
                  <extension key="db-column">
                    <extension key="db-type" value="SMALLINT" />
                    <extension key="db-column-name" value="voa_version" />
                  </extension>
                </field>
                <field name="version">
                  <extension key="db-column">
                    <extension key="db-type" value="INTEGER" />
                    <extension key="db-column-name" value="Version" />
                  </extension>
                </field>
                <extension key="db-key-generator" value="AUTOINC" />
                <extension key="db-optimistic-locking" value="version">
                  <extension key="field-name" value="version" />
                </extension>
              </class>
              <class name="Customer">
                <extension key="db-do-not-create-table" value="true" />
                <extension key="db-table-name" value="Customer" />
                <field name="id" null-value="exception">
                  <extension key="db-column">
                    <extension key="db-type" value="INTEGER" />
                    <extension key="db-column-name" value="ID" />
                  </extension>
                </field>
                <field name="address">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="Address" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="birthDate">
                  <extension key="db-column">
                    <extension key="db-type" value="TIMESTAMP" />
                    <extension key="db-column-name" value="BirthDate" />
                  </extension>
                </field>
                <field name="city">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="City" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="contactName">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="ContactName" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="country">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="Country" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="customerCode">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="CustomerCode" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="customerName">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="CustomerName" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="email">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="Email" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="fax">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="Fax" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="isActive">
                  <extension key="db-column">
                    <extension key="db-type" value="TINYINT" />
                    <extension key="db-column-name" value="IsActive" />
                  </extension>
                </field>
                <field name="telephone">
                  <extension key="db-column">
                    <extension key="db-type" value="VARCHAR" />
                    <extension key="db-column-name" value="Telephone" />
                    <extension key="db-length" value="255" />
                  </extension>
                </field>
                <field name="version2" null-value="exception">
                  <extension key="db-column">
                    <extension key="db-type" value="SMALLINT" />
                    <extension key="db-column-name" value="voa_version" />
                  </extension>
                </field>
                <field name="version">
                  <extension key="db-column">
                    <extension key="db-type" value="INTEGER" />
                    <extension key="db-column-name" value="Version" />
                  </extension>
                </field>
                <extension key="db-key-generator" value="AUTOINC" />
                <extension key="db-optimistic-locking" value="version">
                  <extension key="field-name" value="version" />
                </extension>
              </class>
            </namespace>
          </mapping>
        </mappings>
      </openaccess>
    </configuration>



    2nd app.config(AppConnection.Config

      <connections>
          <connection id="SentientConnection2">
            <databasename>Sentient.Data.Core</databasename>
            <servername>intprmunar\sql08</servername>
            <integratedSecurity>False</integratedSecurity>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
            <user>pmunar</user>
            <password>pmunar</password>
          </connection>
          <connection id="SentientConnection">
            <connectionString>Data Source=INTJLMUTIA\SQLSVR2008;Initial Catalog=Sentient.Data.Core;Integrated Security=True</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
      </openaccess>




    2nd app.config (AppConnection.Config)

      <connections>
          <connection id="SentientConnection2">
            <databasename>Sentient.Data.Core</databasename>
            <servername>intprmunar\sql08</servername>
            <integratedSecurity>False</integratedSecurity>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
            <user>pmunar</user>
            <password>pmunar</password>
          </connection>
          <connection id="SentientConnection">
            <connectionString>Data Source=INTJLMUTIA\SQLSVR2008;Initial Catalog=Sentient.Data.Core;Integrated Security=True</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
      </openaccess>

    But when i select check settings of telerik it cant read the appconnection.config file and it throws 
    Validator           : <connections> section
    Description         : 'Connections' node not present in config 
                           file.
    but i managed the project to run but im not surprise that it throws me an error in the scopeprovider1 class in this part of the code


    static public Database Database()
        {
            if( theObjectScopeProvider1 == null )
                theObjectScopeProvider1 = new ObjectScopeProvider1();
     
            if( theObjectScopeProvider1.myDatabase == null )
                theObjectScopeProvider1.myDatabase = Telerik.OpenAccess.Database.Get( "SentientConnection" );
     
            return theObjectScopeProvider1.myDatabase;
        }


    it points in the get function saying "The 'openaccess' section cannot be found in the application's configuration file." which infact as what you can see at the above two configs had an openaccess section.. can the telerik team provide some example project for this please? thnx


    also i just received this error "The connection section with id 'SentientConnection2' cannot be found in the configuration files traversed from '(.NET application config file)'." does it mean that open access cannot support the "configSource" functionallity?
  5. Petko_I
    Admin
    Petko_I avatar
    184 posts

    Posted 02 Aug 2010 Link to this post

    Hello Joebet,

    In fact configSource is an attribute of the connectionStrings node, not the connections node of the OpenAccess configuration. I am afraid that the connections section with the connection id must be specified explicitly in the App.config file of your main application. Currently, I cannot think of a way to remove it from this file. However, you can extract the connection string in a separate file and then reference it with a configSource but the new file containing the connection string must have a specific format:

    <connectionStrings>
      <add name="DatabaseConnection1" connectionString="data source=.\SQLEXPRESS;initial catalog=NorthwindOA;integrated security=True" providerName="System.Data.SqlClient" />
    </connectionStrings>

    The only content of the file must be the connectionStrings section. One thing I want to highlight is that you can delete all the data about the connection in the configuration file where the mapping is given (the class library configuration file). The connection string specified in the OpenAccess configuration has lower priority than the one specified in the global connectionStrings section. It is used only in case when a connection with the needed id is not found in the global section.

    There is a topic in our online help which can give you some ideas on how to separate the configuration information across different files. What is more, I am giving you an example project for removing the connection string info from the App.config.

    I hope these resources will give you a general idea of how the configurations should look like. Should you need further assistance, do not hesitate to contact us.


    Best wishes,
    Petko_I
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top