End-user defined database names

Thread is closed for posting
10 posts, 0 answers
  1. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 08 Jul 2009 Link to this post

    I'm working on an application that lets users create database files with any name, based on the persistent classes defined in the application. Can OpenAccess handle this scenario?

    The VSchema command creates a database with the name specified in App.config. I see that you can use an XMLElement to override that information, but the Help topic says "None of the OpenAccess ORM tools can read the passed config override". But can you use the database name in App.config to develop the application at design time, and then override the configuration with the user-defined name at runtime?
  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 14 Jul 2009 Link to this post

    Hi Denis Vulinovich,
    The xml fragment that you pass into the Database.Get method will overwrite the app.config content. You can use that way during runtime and the app.config way during development.

    There is also a new schema api that can be used to create and update the databases directly from your application. Please have a look here:

    http://www.telerik.com/help/openaccess-orm/telerik.openaccess-telerik.openaccess.database-getschemahandler.html

    The ISchemaHandler contains information about all funtions.

    Greetings,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 28 Aug 2009 Link to this post

    I've just tried to use GetSchemaHandler with the following code:

    Telerik.OpenAccess.Database db = Telerik.OpenAccess.Database.Get( "IntegratorConnection" ); 
    if ( db.GetSchemaHandler().DatabaseExists() == false ) 
       db.GetSchemaHandler().CreateDatabase(); 
     

    But I get a ConfigurationException when it executes either of db.GetSchemaHandler() statements, with the message "The 'openaccess' section cannot be found in the application's configuration file". Here's App.config for that data access project:

    <?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> 
      <openaccess xmlns="http://www.telerik.com/OpenAccess"
        <references> 
          <reference assemblyname="Management" configrequired="True" /> 
        </references> 
        <connections> 
          <connection id="IntegratorConnection"
            <databasename>Integrator</databasename> 
            <servername>localhost</servername> 
            <integratedSecurity>True</integratedSecurity> 
            <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> 

    If I run the Check Settings utility on my solution, it finds no errors.
  4. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 03 Sep 2009 Link to this post

    Hi Denis Vulinovich,

    This could be a problem if you call this code from assembly that does not reference the OpenAccess persistent classes assembly. What is your exact scenario? Are you maybe using ASP .NET web site? I see you are also referencing a "Management" assembly are you calling it from there?


    All the best,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 03 Sep 2009 Link to this post

    Hi Zoran,

    It's a Windows Forms application. The persistent classes are in the Management assembly, and this assembly only does data access.

    Denis
  6. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 04 Sep 2009 Link to this post

    Hello Denis Vulinovich,

    Does the Management assembly contain an ObjectScopeProvider helper class. If it doesn't, you can try generating it and before executing any OpenAccess related logic, try calling the AdjustForDynamicLoad() method of the ObjectScopeProvider.

    Kind regards,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 04 Sep 2009 Link to this post

    Hi Zoran,

    Thanks for your reply. I've added an ObjectScopeProvider helper class to the Management assembly, and at the start of my testI call AdjustForDynamicLoad(string myPath), which I've copied from the help topic "How to: Dynamically Manage a Connection to a Data Store". Now the following exception occurs when it executes db.GetSchemaHandler().CreateDatabase():

    Telerik.OpenAccess.RT.sql.SQLException: An attempt to attach an auto-named database for file C:\...\TestDb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. 

    But the database file doesn't exist, and in other tests I successfully use a SQL script to create a database with the same path.

    Denis

  8. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 08 Sep 2009 Link to this post

    This error seems to occur when the configuration string includes the Xml tag:

    <connectionParams>AttachDbFilename=C:\SQLServer\TestDb.mdf;</connectionParams> 

    If I leave out this tag, it successfully creates the database in the default data directory. Unfortunately, that's not where I want it...

    Denis
  9. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 10 Sep 2009 Link to this post

    Hello Denis Vulinovich,

    If you use forward mapping and want OpenAccess to create the database for you, then it will always reside in the default directory.
    <connectionParams>AttachDbFilename=C:\SQLServer\TestDb.mdf;</connectionParams>  
    The above entry tells OpenAccess to attach the specified database file but the file should already exist. What you can do is placing an empty database file in the wanted location and then let OpenAccess create the schema (tables) for you.

    Greetings,
    Zoran
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Denis Vulinovich
    Denis Vulinovich avatar
    29 posts
    Member since:
    Jun 2009

    Posted 11 Sep 2009 Link to this post

    Hi Zoran,

    It's now working using the following code:
    ObjectScopeProvider1.AdjustForDynamicLoad( dbName, dbPath ); 
     : 
     : 
    Db.Create( dbName, dbPath );        // Executes SQL script to create database 
    Telerik.OpenAccess.Database db =  
        Telerik.OpenAccess.Database.Get( "IntegratorConnection" ); 
    string ddl = db.GetSchemaHandler().CreateUpdateDDLScript( null ); 
    if ( string.IsNullOrEmpty( ddl ) == false ) 
        db.GetSchemaHandler().ExecuteDDLScript( ddl ); 
     
     

    Thanks for your help.

    Regards,
    Denis


Back to Top