Connecting to Oracle using Oracle.ManagedDataAccess

前端 未结 4 1611
时光说笑
时光说笑 2021-01-04 01:43

I am using Oracle.ManagedDataAccess Nuget Package Version 12.1.022 in my C# (.NET 4.0) project. The package automatically creates entries in the app.config file. How can I r

4条回答
  •  囚心锁ツ
    2021-01-04 02:10

    You can make a separate class file returning the connectionstring like this -

    public class OracleDbConnection
    {
     public static OracleConnection GetConnection()
     {
      const string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=PROD))); User Id=userId;Password=password;";
      var connection=new OracleConnection(connectionString);
      return connection;
     }
    }
    

    Then you can call it like this where you need to access oracle db-

    var oracleConnection = OracleDbConnection.GetConnection();
    oracleConnection.Open();
    

提交回复
热议问题