This is a migrated thread and some comments may be shown as answers.

End-user defined database names

9 Answers 145 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Denis Vulinovich
Top achievements
Rank 1
Denis Vulinovich asked on 09 Jul 2009, 02:59 AM
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?

9 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 14 Jul 2009, 02:33 PM
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.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 28 Aug 2009, 09:29 PM
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.
0
Zoran
Telerik team
answered on 03 Sep 2009, 03:19 PM
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.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 03 Sep 2009, 06:27 PM
Hi Zoran,

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

Denis
0
Zoran
Telerik team
answered on 04 Sep 2009, 07:27 AM
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.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 04 Sep 2009, 09:23 AM
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

0
Denis Vulinovich
Top achievements
Rank 1
answered on 08 Sep 2009, 07:36 AM
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
0
Zoran
Telerik team
answered on 10 Sep 2009, 09:04 AM
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.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 11 Sep 2009, 10:08 AM
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


Tags
General Discussions
Asked by
Denis Vulinovich
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Denis Vulinovich
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or