how to replace code that uses now obsolete System.Data.OracleClient namespace classes?

1.1k views Asked by At

I've made a "generic" program that converts data from a db to another. It uses configuration files to define the conversion. It uses code like this:

static DbProviderFactory _srcProvFactory;
static DbProviderFactory _trgtProvFactory;

public static bool DoConversions()
{
    try
    {
        if (!InitConfig())
            return false;

        _srcProvFactory = DbProviderFactories.GetFactory(GetConnectionClassTypeByDatabaseType(Preferences.SourceDatabaseType));

        _trgtProvFactory = DbProviderFactories.GetFactory(GetConnectionClassTypeByDatabaseType(Preferences.TargetDatabaseType));

        using (DbConnection srcCnctn = _srcProvFactory.CreateConnection(),
               trgtCnctn = _trgtProvFactory.CreateConnection())
        {
            srcCnctn.ConnectionString = Preferences.SourceConnectionString;
            srcCnctn.Open();
            trgtCnctn.ConnectionString = Preferences.TargetConnectionString;
            trgtCnctn.Open();

            //DO STUFF
        }
   }
}

Above GetConnectionClassTypeByDatabaseType-method return strings like "System.Data.OracleClient" depending on config file.

The DO STUFF part calls methods like one below (there's many of these) to find out database table column properties from schema. This is needed cause Oracle, SQL server etc. handle these differently.

public static int GetColumnMaxStringLength(DbProviderFactory provFactory, DataRow schemaTableRow)
{
    if (provFactory is OracleClientFactory)
    {
        return Convert.ToInt32(schemaTableRow["LENGTH"]);
    }
    else if // OTHER OPTIONS
      ...    
    throw new Exception(string.Format("Unsupported DbProviderFactory -type: {0}", provFactory.GetType().ToString()));
}

So how this is supposed to be fixed now when the build says these classes are obsolete? This was supposed to be kind of text book solution when I did this (Pro C# 2008 and the .NET 3.5 Platform). Now I'm baffled.

Thanks in advance & Best Regards - Matti

1

There are 1 answers

0
MatthewMartin On

ODP.NET or any of the other 3rd party ADO.NET driver providers:

ref: Comparison of 3rd Party Oracle .NET Providers