开发者

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

开发者 https://www.devze.com 2023-04-13 06:31 出处:网络
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:

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 st开发者_如何学编程atic 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


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

ref: Comparison of 3rd Party Oracle .NET Providers

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号