Configureless connections

2 posts, 0 answers
  1. Eddie Conner
    Eddie Conner avatar
    32 posts
    Member since:
    Dec 2009

    Posted 21 Jul 2010 Link to this post

    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.
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 22 Jul 2010 Link to this post

    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
  3. DevCraft banner
Back to Top