Changing The Application DataProvider from SQL to Oracle

2 posts, 0 answers
  1. Mohamed
    Mohamed avatar
    1 posts
    Member since:
    Feb 2014

    Posted 10 Mar 2014 Link to this post

    Hi everybody
    I built web project and used Telerik DataAccess tool to build the model (DAL), i built model first and then create the database tables on SQL Server and then Oracle as well
    my problem is, i want the same model project dll to serve both SQL and Oracle DBs by just changing the connection string in web.config and change the data provider to be Oracle or SQL without having to rebuild the data model project every time 
    Simply i want to publish only one project to be able to connect to both Oracle and SQL by just changing configurations 
  2. Boris Georgiev
    Boris Georgiev avatar
    190 posts

    Posted 12 Mar 2014 Link to this post

    Hello Mohamed,

    You can achieve this behavior using Telerik Data Access following next steps:

    1) You should have two connection strings in the app/web config file.
    2) Extend the context class with a partial class, where you should create a new constructor.
    3) You should have two static methods which returns BackendConfiguration - one for Oracle and one for SQL Server and pass this configuration when you call the constructor.

    The new partial class should look like:
    01.public partial class EntitiesModel
    03.    public EntitiesModel(string connection, BackendConfiguration backendConfiguration)
    04.        : base(connection, backendConfiguration, metadataSource)
    05.    { }
    07.    public static BackendConfiguration GetOracleBackendConfiguration()
    08.    {
    09.        BackendConfiguration backend = new BackendConfiguration();
    10.        backend.Backend = "oracle";
    11.        backend.ProviderName = "Oracle.DataAccess.Client";
    12.        backend.Runtime.ReturnNullForRowNotFound = true;
    13.        ...           
    14.        return backend;
    15.    }
    17.    public static BackendConfiguration GetSqlServerBackendConfiguration()
    18.    {
    19.        BackendConfiguration backend = new BackendConfiguration();
    20.        backend.Backend = "mssql";
    21.        backend.ProviderName = "System.Data.SqlClient";
    22.        backend.Runtime.ReturnNullForRowNotFound = true;
    23.        ...
    24.        return backend;
    25.    }

    I hope that helps.

    Boris Georgiev
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  3. DevCraft banner
Back to Top