项目需要和第三方进行对接,奇葩的是地方没给提供接口,却提供了一个Oracle的视图
所以有了C#访问Oracle数据库的需求
1.打开nuget,安装驱动
https://www.nuget.org/packages/Oracle.ManagedDataAccess/
2.写代码
using System; using Oracle.DataAccess.Client; class Sample { static void Main() { // Connect to Oracle string constr = "User Id=ip/scott;Password=tiger;Data Source=oracle"; OracleConnection con = new OracleConnection(constr); con.Open(); // Display Version Number Console.WriteLine("Connected to Oracle " + con.ServerVersion); // Close and Dispose OracleConnection con.Close(); con.Dispose(); } }
参考地址:https://docs.oracle.com/database/121/ODPNT/intro005.htm#ODPNT148