连接到Oracle与odp.net和OCI从C# [英] Connect to Oracle with odp.net and the OCI from C#

查看:420
本文介绍了连接到Oracle与odp.net和OCI从C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读有关如何从我的C#Windows应用程序连接到我的Oracle数据库,但我一直碰壁。我决定用odp.net和OCI,使得客户端计算机不是需要安装客户端,但我不能让它的工作。

I have been reading about how to connect to my oracle database from my C# win application, but I keep "hitting the wall". I have decided to use odp.net and OCI, such that the client computer not needs to install a client, but I can’t get it to work.

我有一个小的测试应用程序,如下图所示我的code和我的解决方案我已经加入以下的DLL从Oracle OCI:OCI.DLL,orannzsbb11.dll和oraociicus11.dll。他们都与最后的.exe文件放在一起。

I have a small test application, the code I shown below and in my solution I have added the following dll’s from oracle OCI: oci.dll, orannzsbb11.dll and oraociicus11.dll. They are all placed together with the final .exe file.

测试code:

private static string CONNECTION_STRING =
                  "User Id=hr;Password=hr;Data Source=(DESCRIPTION=" +
                  "(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))" +
                  "(CONNECT_DATA=(SID=XE)));Connect Timeout=15;";

        static void Main(string[] args)
        {
            try
            {
                using (var conn = new OracleConnection(CONNECTION_STRING))
                {
                    conn.Open();
                    Console.WriteLine("Connection is: {0}", conn.State.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

已经出现在使用(...)语句的问题,程序只是停止工作,我没有得到任何回应。什么是我需要做的就是保监处的工作???魔术

The problem occurs already in the using(…) statement, the program just stop working and I get no response. What is the magic that I need to do to get the OCI to work???

推荐答案

要能够使用ODP.NET无需安装完全成熟的客户端,您需要使用的 Oracle即时客户端包(你不能只是库从一个完整的客户端复制):

To be able to use ODP.NET without installing the full blown client, you need to use the Oracle Instant Client packages (you cannot just copy the libraries from a complete client):

  • <一个href="http://stackoverflow.com/questions/70602/what-is-the-minimum-client-footprint-required-to-connect-c-to-an-oracle-database/70901#70901">Check此处的要求的说明。
  • 与Oracle V10开始,我会强烈建议使用的 EZCONNECT 以简化您的连接字符串。这个怎么样:

  • Check here for a description of the requirements.
  • Starting with Oracle v10, I would strongly recommend using EZCONNECT to simplify your connection string. How about this:

private const string CONNECTION_STRING="User Id=hr;Password=hr;"+
   +"Data Source=127.0.0.1:1521/XE;Connect Timeout=15;";

这篇关于连接到Oracle与odp.net和OCI从C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆