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

Configureless connections

1 Answer 48 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.
Eddie Conner
Top achievements
Rank 1
Eddie Conner asked on 21 Jul 2010, 06:57 AM
Is it possible to set the database connections in code and not use them in the config file? Also, can the connections be switched between different databases via code? For example, one client uses MS SQL and another wants to use MySQL.

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 22 Jul 2010, 02:28 PM
Hello Eddie Conner,

Yes it is possible to set the database connection in the code. You should instantiate the OpenAccessContext instance using the following approach:

...
string connectionString = @"data source=.\SQLEXPRESS;initial catalog=Northwind;integrated security=True";
  
BackendConfiguration backend = new BackendConfiguration();
backend.Backend = "mssql";
  
MetadataSource metadataSource = XmlMetadataSource.FromAssemblyResource("NorthwindModel.rlinq");
  
using (NorthwindContext context = new NorthwindContext(connectionString, backend, metadataSource))
{
    ...
}
...

We have prepared a sample application which demonstrates this scenario.
Hope that helps. Do not hesitate to write again if you have more questions.

Best wishes,
Damyan Bogoev
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
Eddie Conner
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or