connection strings in web.config file

2 posts, 0 answers
  1. Robert
    Robert avatar
    21 posts
    Member since:
    Feb 2009

    Posted 16 Sep 2010 Link to this post

    Hi,

    I would like to have openaccess connection strings in web.config file instead of App.config. I have a website and two class library projects:

    DataClasses - persistent classes
    DataManager - data access code

    configs look like this:

    web.config:

      
    <configuration>
        <configSections>
        <section name="openaccess" type="Telerik.OpenAccess.Config.ConfigSectionHandler,Telerik.OpenAccess.Config, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7ce17eeaf1d59342"/>
        </configSections>
    ...
     
     <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <connections>
          <connection id="k2shopConnection">
            <connectionString>data source=217.73.17.132;initial catalog=eshop;persist security info=True;user id=sa;password=qwe123+</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
          <connection id="DatabaseConnection1">
            <connectionString>Data Source=217.73.17.132;Initial Catalog=eshop;Persist Security Info=True;User ID=sa;Password=qwe123+</connectionString>
            <backendconfigurationname>mssqlConfiguration</backendconfigurationname>
          </connection>
        </connections>
        <references>
          <reference assemblyname="DataManager" configrequired="True" />
          <reference assemblyname="DataClasses" configrequired="True" />
        </references>
      </openaccess>

    DataClasses App.config:

    <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>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references />
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
            <option.Multithreaded>False</option.Multithreaded>
            <l2CacheEnabled>True</l2CacheEnabled>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
    ....
     </mappings>
      </openaccess>
    </configuration>

    DataManager App.config:

    <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>
      <openaccess xmlns="http://www.telerik.com/OpenAccess">
        <references>
          <reference assemblyname="DataClasses" configrequired="True" />
        </references>
        <backendconfigurations>
          <backendconfiguration id="mssqlConfiguration" backend="mssql">
            <mappingname>mssqlMapping</mappingname>
            <option.Multithreaded>False</option.Multithreaded>
            <l2CacheEnabled>True</l2CacheEnabled>
          </backendconfiguration>
        </backendconfigurations>
        <mappings current="mssqlMapping">
          <mapping id="mssqlMapping" />
        </mappings>
      </openaccess>
    </configuration>

    when I compile I get following error:

    Error 143 OpenAccess Error: 
    The following problem(s) have occurred :

    1. The connection section with id 'DatabaseConnection1' cannot be found in the configuration files traversed from 'C:\Users\Remote\Documents\Visual Studio 2010\Projects\k2shop\k2shop\Projects\k2shop\DataManager\App.config'.

    See History property for more details.Verify that a connection section with the same id as the one specified  in the 'ConnectionId' project property exists in the configuration file. DataManager


    What am I doing wrong?

    Thanks,
    Robert
  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 17 Sep 2010 Link to this post

    Hello Robert,

    Please make sure that the UpdateDatabase property is disabled for all projects. This property should be visible in the Properties pane of Visual Studio when a project is selected.
    Optionally, you can remove the backendconfigurations and mappings nodes from the DataManager's App.config, as well as the whole openaccess node from the web.config. In order to use a connection string from the web.config, the only thing you should do is to copy it there and make sure it has the correct name. This connection string is treated with higher priority by the runtime than the connection string specified in the App.config files. You can also have a look at the attached project, which demonstrates the correct setup.
    Hope that helps.

    All the best,
    Alexander
    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. DevCraft banner
Back to Top