将 C# 连接到 Oracle 数据库所需的最小客户端占用空间是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/70602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the minimum client footprint required to connect C# to an Oracle database?
提问by Jonathan
I have successfully connected to an Oracle database (10g) from C# (Visual Studio 2008) by downloading and installing the client administration tools and Visual Studio 2008 on my laptop.
通过在我的笔记本电脑上下载并安装客户端管理工具和 Visual Studio 2008,我已成功地从 C# (Visual Studio 2008) 连接到 Oracle 数据库 (10g)。
The installation footprint for Oracle Client tools was over 200Mb, and quite long winded.
Oracle 客户端工具的安装占用空间超过 200Mb,而且相当冗长。
Does anyone know what the minimum workable footprint is? I am hoping that it's a single DLL and a register command, but I have the feeling I need to install an oracle home, and set various environment variables.
有谁知道最小可行的足迹是多少?我希望它是一个单独的 DLL 和一个注册命令,但我觉得我需要安装一个 oracle home,并设置各种环境变量。
I am using Oracle.DataAccess in my code.
我在我的代码中使用 Oracle.DataAccess。
采纳答案by Mac
You need an Oracle Client to connect to an Oracle database. The easiest way is to install the Oracle Data Access Components.
您需要一个 Oracle 客户端来连接到 Oracle 数据库。最简单的方法是安装Oracle 数据访问组件。
To minimize the footprint, I suggest the following :
为了尽量减少足迹,我建议如下:
- Use the Microsoft provider for Oracle (System.Data.OracleClient), which ships with the framework.
- Download the Oracle Instant Client Package- Basic Lite : this is a zip file with (almost) the bare minimum. I recommend version 10.2.0.4, which is much smaller than version 11.1.0.6.0.
- Unzip the following files in a specific folder :
- v10 :
- oci.dll
- orannzsbb10.dll
- oraociicus10.dll
- v11 :
- oci.dll
- orannzsbb11.dll
- oraociei11.dll
- v10 :
- On a x86 platform, add the CRT DLL for Visual Studio 2003 (msvcr71.dll) to this folder, as Oracle guys forgot to read this...
- Add this folder to the PATH environment variable.
- Use the Easy Connect Namingmethod in your application to get rid of the infamous TNSNAMES.ORA configuration file. It looks like this :
sales-server:1521/sales.us.acme.com
.
- 使用 Microsoft 的 Oracle 提供程序 (System.Data.OracleClient),它随框架一起提供。
- 下载Oracle Instant Client Package- 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
- v10:
- 在 x86 平台上,将 Visual Studio 2003 (msvcr71.dll) 的 CRT DLL 添加到此文件夹中,因为 Oracle 人员忘记阅读此内容...
- 将此文件夹添加到 PATH 环境变量。
- 在您的应用程序中使用Easy Connect Naming方法来摆脱臭名昭著的 TNSNAMES.ORA 配置文件。它看起来像这样:
sales-server:1521/sales.us.acme.com
。
This amounts to about 19Mb(v10).
这相当于大约19Mb(v10)。
If you do not care about sharing this folder between several applications, an alternative would be to ship the above mentioned DLLs along with your application binaries, and skip the PATH setting step.
如果您不关心在多个应用程序之间共享此文件夹,另一种方法是将上述 DLL 与您的应用程序二进制文件一起发送,并跳过 PATH 设置步骤。
If you absolutely need to use the Oracle provider (Oracle.DataAccess), you will need :
如果您绝对需要使用 Oracle 提供程序 (Oracle.DataAccess),您将需要:
- ODP .NET 11.1.0.6.20 (the first version which allegedly works with Instant Client).
- Instant Client 11.1.0.6.0, obviously.
- ODP .NET 11.1.0.6.20(据称适用于 Instant Client 的第一个版本)。
- Instant Client 11.1.0.6.0,显然。
Note that I haven't tested this latest configuration...
请注意,我尚未测试此最新配置...
回答by Jonathan
ODAC xcopy will get you away with about 45MB. http://www.oracle.com/technology/software/tech/windows/odpnet/index.html
ODAC xcopy 将为您提供大约 45MB 的空间。 http://www.oracle.com/technology/software/tech/windows/odpnet/index.html
回答by Jonathan
DevArt http://www.devart.com/, formerly CoreLab (crlab.com) supplies a pure-C# Oracle client. That's a single dll, and it works fine.
DevArt http://www.devart.com/,以前的 CoreLab (crlab.com) 提供纯 C# Oracle 客户端。那是一个单独的 dll,它运行良好。
回答by Fidel
This way allows you to connect with ODP.net using 5 redistributable files from oracle:
这种方式允许您使用来自 oracle 的 5 个可再发行文件连接 ODP.net:
Chris's blog entry: Using the new ODP.Net to access Oracle from C# with simple deployment
Chris 的博客文章:使用新的 ODP.Net 通过简单的部署从 C# 访问 Oracle
Edit: In case the blog every goes down, here is a brief summary...
编辑:以防博客每次宕机,这里是一个简短的总结......
- oci.dll
- Oracle.DataAccess.dll
- oraociicus11.dll
- OraOps11w.dll
- orannzsbb11.dll
- oraocci11.dll
- ociw32.dll
- 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
确保您从相同的 ODP.Net / ODAC 发行版中获取所有这些 DLL 以避免版本号冲突,并将它们全部放在与您的 EXE 相同的文件夹中
回答by Vincent De Smet
I found this post on the Oracle forum very usefull as well:
我发现 Oracle 论坛上的这篇文章也非常有用:
How to setup Oracle Instant Client with Visual Studio
如何使用 Visual Studio 设置 Oracle Instant Client
Remark: the ADO.NET team is deprecating System.Data.OracleClient so for future projects you should use ODP.NET
备注:ADO.NET 团队正在弃用 System.Data.OracleClient 所以对于未来的项目你应该使用 ODP.NET
Reproduction:
再生产:
Setup the following environment variables:
- make sure no other oracle directory is in your PATH
- set your PATHto point to your instant client
- set your TNS_ADMINto point to where you tnsnames.ora file is located
- set your NLS_LANG
- set your ORACLE_HOMEto 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.
设置以下环境变量:
- 确保您的 PATH 中没有其他 oracle 目录
- 将您的PATH设置为指向您的即时客户端
- 将TNS_ADMIN 设置为指向 tnsnames.ora 文件所在的位置
- 设置你的NLS_LANG
- 将您的ORACLE_HOME设置为您的即时客户端
对我来说,我将 NLS_LANG 设置为
http://download-east.oracle.com/docs/html/A95493_01/gblsupp.htm#634282
我通过使用即时客户端的 sqlplus 附加组件来验证这是使用正确的客户端软件。
对我来说,我设置:SET NLS_LANG=AMERICAN_AMERICA.WE8MSWIN1252
注意:在进行任何更改之前,请备份您的 Oracle 注册表项(如果存在)并备份所有环境变量的字符串。
回答by kol
I use the method suggested by Pandicus above, on Windows XP, using ODAC 11.2.0.2.1. The steps are as follows:
我使用 Pandicus 建议的方法,在 Windows XP 上,使用 ODAC 11.2.0.2.1。步骤如下:
- Download the "ODAC 11.2 Release 3 (11.2.0.2.1) with Xcopy Deployment" package from oracle.com (53 MB), and extract the ZIP.
- Collect the following DLLs: oci.dll (1 MB), oraociei11.dll (130 MB!), OraOps11w.dll (0.4 MB), Oracle.DataAccess.dll (1 MB). The remaining stuff can be deleted, and nothing have to be installed.
- Add a reference to Oracle.DataAccess.dll, add
using Oracle.DataAccess.Client;
to your code and now you can use types likeOracleConnection
,OracleCommand
andOracleDataReader
to access an Oracle database. See the class documentationfor details. There is no need to use the tnsnames.ora configuration file, only the connection string must be set properly. - The above 4 DLLs have to be deployed along with your executable.
- 从 oracle.com (53 MB) 下载“ODAC 11.2 Release 3 (11.2.0.2.1) with Xcopy Deployment”包,并解压 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;
到您的代码,现在你可以使用类型,如OracleConnection
,OracleCommand
和OracleDataReader
访问Oracle数据库。有关详细信息,请参阅类文档。不需要使用 tnsnames.ora 配置文件,只需正确设置连接字符串即可。 - 上述 4 个 DLL 必须与您的可执行文件一起部署。
回答by DavidRR
Here is an update for Oracle 11.2.0.4.0. I had success with the following procedure on Windows 7using System.Data.OracleClient
.
这是Oracle 11.2.0.4.0的更新。我在Windows 7 上使用System.Data.OracleClient
.
1.Download Instant Client Package - Basic Lite: Windows 32-Bitor 64-Bit.
1.下载Instant Client Package - Basic Lite:Windows 32 位或64 位。
2.Copy the following files to a location in your system path:
2.将以下文件复制到系统路径中的某个位置:
32-Bit
32位
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-Bit
64 位
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.Construct a connection string that omits the need for tnsnames.ora.
3.构建一个不需要tnsnames.ora的连接字符串。
(See examples in the test program below.)
(请参阅下面测试程序中的示例。)
4.Run this minimal C# program to test your installation:
4.运行这个最小的 C# 程序来测试你的安装:
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);
}
}
Final tip:If you encounter the error "System.Data.OracleClient requires Oracle client software version 8.1.7", see this question.
最后提示:如果您遇到错误“System.Data.OracleClient requires Oracle client software version 8.1.7”,请参阅此问题。
回答by ecoe
As of 2014, the OPD.NET, Managed Driver is the smallest footprint.
截至 2014 年,OPD.NET 托管驱动程序占用空间最小。
Here is a code usage comparison to the non-managed versions that previous (outdated) answers suggested: http://docs.oracle.com/cd/E51173_01/win.122/e17732/intro005.htm#ODPNT148
这是与以前(过时)答案建议的非托管版本的代码用法比较:http: //docs.oracle.com/cd/E51173_01/win.122/e17732/intro005.htm#ODPNT148
You will need to download these dlls and reference Oracle.ManagedDataAccess.dll
in your project:
Download the ODP.NET, Managed Driver Xcopy version only
您将需要下载这些 dll 并Oracle.ManagedDataAccess.dll
在您的项目中引用:仅下载ODP.NET,托管驱动程序 Xcopy 版本
Here is a typical foot print you will need to package with your release:
以下是您需要随发行版打包的典型足迹:
Oracle.ManagedDataAccess.dll
Oracle.ManagedDataAccessDTC.dll
Oracle.ManagedDataAccess.dll
Oracle.ManagedDataAccessDTC.dll
all together, a whopping6.4 MB for .Net 4.0.
总之,.Net 4.0的空间高达6.4 MB。