Connecting to Oracle Database through C#?

后端 未结 5 1905
感动是毒
感动是毒 2020-11-28 05:41

I need to connect to a Oracle DB (external) through Visual Studio 2010. But I dont want to install Oracle on my machine. In my project I referenced: System.Data.Ora

5条回答
  •  孤独总比滥情好
    2020-11-28 06:25

    First off you need to download and install ODP from this site http://www.oracle.com/technetwork/topics/dotnet/index-085163.html

    After installation add a reference of the assembly Oracle.DataAccess.dll.

    Your are good to go after this.

    using System; 
    using Oracle.DataAccess.Client; 
    
    class OraTest
    { 
        OracleConnection con; 
        void Connect() 
        { 
            con = new OracleConnection(); 
            con.ConnectionString = "User Id=;Password=;Data Source="; 
            con.Open(); 
            Console.WriteLine("Connected to Oracle" + con.ServerVersion); 
        }
    
        void Close() 
        {
            con.Close(); 
            con.Dispose(); 
        } 
    
        static void Main() 
        { 
            OraTest ot= new OraTest(); 
            ot.Connect(); 
            ot.Close(); 
        } 
    }
    

提交回复
热议问题