主要的是要做三件工作: 打包文件,写注册表,注册环境变量
说明:我的oracle版本为9, 在2000 advanced server 上测试通过,可以正常创建数据库连接
1.打包文件
目录结果如下图所示
以下是我的打包程序中的文件目录,
bin : 最重要的当然是bin目录,在我的打包程序中,需要29个文件:
--------------------
oci.dll
oraclient9.dll
oracommon9.dll
oracore9.dll
orageneric9.dll
oraldapclnt9.dll
oran9.dll
orancds9.dll
orancrypt9.dll
oranhost9.dll
oranl9.dll
oranldap9.dll
oranls9.dll
oranms.dll
oranmsp.dll
orannts9.dll
orannzsbb9.dll
oranoname9.dll
oranro9.dll
orantcp9.dll
orantns9.dll
orapls9.dll
oraslax9.dll
orasnls9.dll
orasql9.dll
oratrace9.dll
oraunls9.dll
oravsn9.dll
orawtc9.dll
--------------------
network/admin : tnsnames.ora
tnsnames.ora文件内容如下:(service_name = 服务器的连接)
orcl =
(description =
(address_list =
(address = (protocol = tcp)(host = xxx.xxx.xxx.xxx)(port = 1521))
)
(connect_data =
(service_name = orcl)
)
)
ocommon/nls/admin/data: 原oracle安装目录下所有文件
oracore/zoneinfo : timezone.dat
2.写注册表
hkey_local_machine/software/oracle
"oracle_home" = "c:/oracle/ora90"
我发现从网上查到的 hkey_local_machine/software/oracle/home0下的oracle_home值并不是必须的.
3.注册环境变量
hkey_local_machine/system/controlset001/control/session manager/environment
"path" += "d:/oracle/ora90/bin;"
这里需要注意的是最好不用把path直接设成这个值,这样会覆盖掉系统原有的path,所以最好是在原有的path上添加.但是.net安装程序中通过直接设置注册表无法做到,这时候可以通过添加自定义安装操作来在程序中完成.
一个问题是在设置path后不会立即生效,所以安装完程序后,系统找不到oracle的bin目录,无法建立数据库连接. 我现在的做法是把bin目录下的29个文件都拷贝到系统的[system目录](在.net的部署程序中,文件系统->特殊文件夹).有点恶毒阿,不过临时凑活着吧 :) 谁找到解决的办法记得告诉我阿
示例代码如下:
#region 检查oracle客户端设置
///
/// 检查oracle客户端设置
///
private void checkoracleclient() {
string[] keys = { "system", "controlset001", "control", "session manager", "environment" };
this.setregistrykey(registry.localmachine, keys, "path", @"c:/oracle/ora90/bin", true);
keys = new string[] { "software", "oracle"};
this.setregistrykey(registry.localmachine, keys, "oracle_home", @"c:/oracle/ora90", false);
}
///
/// 将指定的值写入注册表
///
/// <param name="startkey">初始的注册表项</param>
/// <param name="registrykeys">注册表项数组,表示了指定值的路径</param>
/// <param name="valuename">值的名称</param>
/// <param name="value">要写入的值</param>
/// <param name="append">是否在当前值前添加,若为否,则覆盖当前值</param>
private void setregistrykey(registrykey startkey, string[] registrykeys, string valuename, string value, bool append) {
registrykey rk = startkey;
registrykey subkey = null;
for (int i=0; i<registrykeys.getlength(0); i++) {
subkey = rk.opensubkey(registrykeys[i], true);
if (subkey == null) {
subkey = rk.createsubkey(registrykeys[i]);
}
rk = subkey;
}
if (append) {
if (rk.getvalue(valuename) == null) {
rk.setvalue(valuename, value);
} else {
string oldvalue = rk.getvalue(valuename).tostring();
if (oldvalue.indexof(value) > 0) {
rk.setvalue(valuename, value + ";" + oldvalue);
}
}
} else {
if (rk.getvalue(valuename) == null) {
rk.setvalue(valuename, value);
rk.flush();
}
}
if (subkey != null) {
subkey.close();
}
rk.flush();
rk.close();
}
#endregion 检查oracle客户端设置