不安装Oracle客户端,那么需要下载oracle instant client包,就可以连接Oracle服务器;
https://www.oracle.com/database/technologies/instant-client/downloads.html
64位的解压到
Application.StartupPath + @"\Oracle64"
32位的解压到
Application.StartupPath + @"\Oracle"
在代码配置进程的环境变量,就可以了。
private void InitOracleEnvironment() { string oraclePath = ""; if (IntPtr.Size == 8) { oraclePath = Application.StartupPath + @"\Oracle64"; } else if (IntPtr.Size == 4) { oraclePath = Application.StartupPath + @"\Oracle"; } Environment.SetEnvironmentVariable("PATH", oraclePath, EnvironmentVariableTarget.Process); Environment.SetEnvironmentVariable("NLS_LANG", "SIMPLIFIED CHINESE_CHINA.ZHS16GBK", EnvironmentVariableTarget.Process); }