【问题标题】:How to avoid ODAC licensing for compilation of code in c#.net Projects如何避免 ODAC 许可在 c#.net 项目中编译代码
【发布时间】:2014-01-28 08:57:50
【问题描述】:

我正在编写使用 postgres 数据库的代码。这段代码已经使用了 oracle 特定的函数,我添加了一些函数来访问 postgres 表。需要进行仅使用 postgres 功能的构建,不需要 oracle 代码行,因此不需要 ODAC。

http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html

有一些选项,比如为 c# 添加条件编译,这样就不会为 postgres 执行 oracle 特定代码。这样做不会在编译的 dll 中添加基于 ODAC 的代码部分,因此不需要 ODAC,但这是唯一的方法。正如我所说,应用程序中有很多项目,进行条件编译会创建很多额外的代码。

或者还有什么可以避免 ODAC 许可的其他替代方案。

谢谢,

function GetData()
{
 if(Postgres flag){
// code for using OracleClientFactory and initlizing the oraclecommand

}
else if(Oracle flag)
{
   // code for using postgres and initlizing the its command object
}


}
 // code to assign query to command object and execute the query
// return the resluts

catch (){}
finally{//dispoing the objects}

}

}

【问题讨论】:

    标签: .net oracle c#-4.0 visual-studio-2012 odac


    【解决方案1】:

    在研究了不同的选项后,一种可能的方法是使用 c# 动态关键字。它将允许我们在运行时获得所需的类型,并且可以修复编译错误。在同一行我们可以使用 ObjectHandle objObjectHandle = Activator.CreateInstance 在运行时创建实例并可以使用 unwrap 函数使用它。

    Using Activator.CreateInstance to get the object type at runtime.

    ObjectHandle objObjectHandle = Activator.CreateInstance("Npgsql","Npgsql.NpgsqlDataAdapter");

    要使用动态关键字,需要使用 Microsoft.CSharp.dll 版本 4,在项目文件中添加其引用。我们正在寻找其他解决方案来创建库项目并为两种类型的数据库制作标准对象模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多