将C#连接到Oracle数据库所需的最小客户端资源是多少?

将C#连接到Oracle数据库所需的最小客户端资源是多少?

What is the minimum client footprint required to connect C# to an Oracle database?

通过在笔记本电脑上下载并安装客户端管理工具和Visual Studio 2008,我已经从C#(Visual Studio 2008)成功连接到Oracle数据库(10g)。

Oracle Client工具的安装占用空间超过200Mb,而且运行时间很长。

有谁知道最小可行的占地面积是多少? 我希望这是一个DLL和一个register命令,但是我感觉我需要安装一个oracle home,并设置各种环境变量。

我在代码中使用Oracle.DataAccess。


您需要一个Oracle Client才能连接到Oracle数据库。最简单的方法是安装Oracle数据访问组件。

为了减少占用空间,我建议如下:

  • 使用框架随附的Microsoft提供程序(Oracle.System.Data.OracleClient)。
  • 下载Oracle Instant Client软件包-Basic Lite:这是一个(几乎)最低要求的zip文件。我建议版本10.2.0.4,比版本11.1.0.6.0小得多。
  • 将以下文件解压缩到特定的文件夹中:

    • v10:

      • oci.dll
      • orannzsbb10.dll
      • oraociicus10.dll
    • v11:

      • oci.dll
      • orannzsbb11.dll
      • oraociei11.dll
  • 在x86平台上,将Visual Studio 2003的CRT DLL(msvcr71.dll)添加到此文件夹,因为Oracle伙计们忘记阅读此文件了。
  • 将此文件夹添加到PATH环境变量中。
  • 在您的应用程序中使用Easy Connect Naming方法来摆脱臭名昭著的TNSNAMES.ORA配置文件。看起来像这样:sales-server:1521/sales.us.acme.com

总计约19Mb(v10)。

如果您不关心在多个应用程序之间共享此文件夹,则可以选择将上述DLL与应用程序二进制文件一起提供,并跳过PATH设置步骤。

如果您绝对需要使用Oracle提供程序(Oracle.DataAccess),则需要:

  • ODP .NET 11.1.0.6.20(据称可与Instant Client一起使用的第一个版本)。
  • 显然,Instant Client 11.1.0.6.0。

请注意,我尚未测试此最新配置...


截至2014年,OPD.NET托管驱动程序是最小的占用空间。

这是代码用法与先前(过时)答案建议的非托管版本的比较:
http://docs.oracle.com/cd/E51173_01/win.122/e17732/intro005.htm#ODPNT148

您将需要在项目中下载这些dll并引用Oracle.ManagedDataAccess.dll
仅下载ODP.NET,托管驱动程序Xcopy版本

这是您需要与发布一起包装的典型足迹:

  • Oracle.ManagedDataAccess.dll
  • Oracle.ManagedDataAccessDTC.dll
  • 总之,.Net 4.0的容量高达6.4 MB。


    我在Windows XP上使用ODAC 11.2.0.2.1使用上述Pandicus建议的方法。步骤如下:

  • 从oracle.com(53 MB)下载"带有Xcopy部署的ODAC 11.2第3版(11.2.0.2.1)"软件包,然后解压缩ZIP。
  • 收集以下DLL:oci.dll(1 MB),oraociei11.dll(130 MB!),OraOps11w.dll(0.4 MB),Oracle.DataAccess.dll(1 MB)。剩余的东西可以删除,无需安装任何东西。
  • 添加对Oracle.DataAccess.dll的引用,将using Oracle.DataAccess.Client;添加到代码中,现在您可以使用OracleConnectionOracleCommandOracleDataReader之类的类型来访问Oracle数据库。有关详细信息,请参见类文档。无需使用tnsnames.ora配置文件,仅必须正确设置连接字符串。
  • 以上4个DLL必须与可执行文件一起部署。

  • 这种方式允许您使用来自oracle的5个可再发行文件与ODP.net连接:

    克里斯的博客文章:使用新的ODP.Net通过简单的部署即可从C#访问Oracle

    编辑:万一每个博客都失败了,这里是一个简短的摘要...

    • oci.dll
    • Oracle.DataAccess.dll
    • oraociicus11.dll
    • OraOps11w.dll
    • orannzsbb11.dll
    • oraocci11.dll
    • ociw32.dll

    make sure you get ALL those DLL's from the same ODP.Net / ODAC distribution to avoid version number conflicts, and put them all in the same folder as your EXE


    DevArt http://www.devart.com/,以前是CoreLab(crlab.com)提供纯C#Oracle客户端。那是一个单一的dll,并且工作正常。


    这是Oracle 11.2.0.4.0的更新。我在Windows 7上使用System.Data.OracleClient成功完成了以下过程。

    1.下载Instant Client Package-Basic Lite:Windows 32位或64位。

    2.将以下文件复制到系统路径中的某个位置:

    32位

    1
    2
    3
    4
    5
     1,036,288  2013-10-11  oci.dll
       348,160  2013-10-11  ociw32.dll
     1,290,240  2013-09-21  orannzsbb11.dll
       562,688  2013-10-11  oraocci11.dll
    36,286,464  2013-10-11  oraociicus11.dll

    64位

    1
    2
    3
    4
    5
       691,712  2013-10-09  oci.dll
       482,304  2013-10-09  ociw32.dll
     1,603,072  2013-09-10  orannzsbb11.dll
     1,235,456  2013-10-09  oraocci11.dll
    45,935,104  2013-10-09  oraociicus11.dll

    3.构造一个不需要tnsnames.ora的连接字符串。

    (请参阅下面的测试程序中的示例。)

    4.运行此最小的C#程序来测试安装:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    using System;
    using System.Data;
    using System.Data.OracleClient;

    class TestOracleInstantClient
    {
        static public void Main(string[] args)
        {
            const string host ="yourhost.yourdomain.com";
            const string serviceName ="yourservice.yourdomain.com";
            const string userId ="foo";
            const string password ="bar";

            var conn = new OracleConnection();

            // Construct a connection string using Method 1 or 2.
            conn.ConnectionString =
                GetConnectionStringMethod1(host, serviceName, userId, password);

            try
            {
                conn.Open();
                Console.WriteLine("Connection succeeded.");
                // Do something with the connection.
                conn.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Connection failed:" + e.Message);
            }
        }

        static private string GetConnectionStringMethod1(
            string host,
            string serviceName,
            string userId,
            string password
            )
        {
            string format =
               "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" +
               "(HOST={0})(PORT=1521))" +
               "(CONNECT_DATA=(SERVER=DEDICATED)" +
               "(SERVICE_NAME={1})));" +
               "uid={2};" +
               "pwd={3};"; // assumes port is 1521 (the default)

            return String.Format(format, host, serviceName, userId, password);
        }

        static private string GetConnectionStringMethod2(
            string host,
            string serviceName,
            string userId,
            string password
            )
        {
            string format =
               "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)" +
               "(HOST={0})(PORT=1521))" +
               "(CONNECT_DATA=(SERVER=DEDICATED)" +
               "(SERVICE_NAME={1})));" +
               "User Id={2};" +
               "Password={3};"; // assumes port is 1521 (the default)

            return String.Format(format, host, serviceName, userId, password);
        }
    }

    最后提示:如果遇到错误" System.Data.OracleClient需要Oracle客户端软件版本8.1.7",请参阅此问题。


    ODAC xcopy将为您提供约45MB的存储空间。
    http://www.oracle.com/technology/software/tech/windows/odpnet/index.html


    我发现在Oracle论坛上的这篇帖子也非常有用:

    如何使用Visual Studio设置Oracle Instant Client

    备注:ADO.NET团队不赞成使用System.Data.OracleClient,因此对于以后的项目,您应该使用ODP.NET

    再生产:

    Setup the following environment variables:

  • make sure no other oracle directory is in your PATH
  • set your PATH to point to your instant client
  • set your TNS_ADMIN to point to where you tnsnames.ora file is
    located
  • set your NLS_LANG
  • set your ORACLE_HOME to your instant client
  • For me, I set NLS_LANG to

    http://download-east.oracle.com/docs/html/A95493_01/gblsupp.htm#634282

    I verified this was using the correct client software by using the sqlplus add-on to the instant client.

    For me, I set:
    SET NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252

    Note: before you make any changes, back up your Oracle registry key (if exist) and backup the string for any environment variables.

    Read the Oracle Instant Client FAQ here


    推荐阅读