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

Open database by code

3 Answers 73 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
ENTERPRISE INTERNATIONAL SAS asked on 15 Mar 2011, 06:12 PM
Hi!

I'm developing in XAML (Window), and I'm noting first time application window runs and is binding elements against ORM assembly (where Entity classes generated from database) fields, window takes more or less 4 or 5 seconds to show elements with data, next time (without exit) same window or another is loaded, time is faster to show window. I'm using a class derived from OpenAccessContext to make any operations (created automatically by OpenAccess). how can I do to open database (I believe caused by this) and close it by code?


thanks

3 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 15 Mar 2011, 09:46 PM
Hello Ramiro,
The database is opened if the first context is accessing the database the first time. We are calculating the metadata in that call so that it is usually longer. What do you want to achieve?

Kind regards,
Jan Blessenohl
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
answered on 12 Apr 2011, 10:36 PM

HI!

I would like to avoid user receive the impact of have to wait first time, so when main app is loading I would like to open database manually at that time. If it is possible I would like to. thanks

0
Alexander
Telerik team
answered on 15 Apr 2011, 02:16 PM
Hello Ramiro,

Yes, this is possible. In the class deriving from OpenAccessContext you should have code similar to this:
private static string connectionStringName = @"AdventureWorksConnection";
private static BackendConfiguration backend = GetBackendConfiguration();
private static MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource("EntityDiagrams1.rlinq");
 
...
 
public static BackendConfiguration GetBackendConfiguration()
{
     BackendConfiguration backend = new BackendConfiguration();
     backend.Backend = "mssql";
     return backend;
}

Those objects are needed to open the database in the context's constructor but you can instantiate them before that and open the database manually. The code you would need is this:
BackendConfiguration backend = new BackendConfiguration();
backend.Backend = "mssql";
 
Assembly domainModelAssembly = typeof(DatabaseLog).Assembly; //Needed if the persistent classes are placed in another assembly; DatabaseLog is one of the persistent classes.
 
MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource(domainModelAssembly, "EntityDiagrams1.rlinq");
 
Database d = Database.Get("AdventureWorksConnection", backend, metadataSource.GetModel());

This would initialize the database instance and associate it with the metadata of the EntityDiagrams1.rlinq model and the creation of the first OpenAccessContext should be much faster.

If you would also like to dispose the database at the end, you can use the following code:
Database database = Database.Get("AdventureWorksConnection");
database.Dispose();
I 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
Tags
Development (API, general questions)
Asked by
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
ENTERPRISE INTERNATIONAL SAS
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or