【问题标题】:ODP.Net Core Appsettings.json Configuration For Oracle Autonomous ConnectionOracle 自治连接的 ODP.Net Core Appsettings.json 配置
【发布时间】:2019-12-17 14:25:34
【问题描述】:

我按照 oracle 的代码示例使用标准连接配置到 oracle db 的连接:

{
  "ConnectionStrings": {
    "DefaultConnection": "User Id=<USER ID>;Password=<PASSWORD>;Data Source=<DATA SOURCE>;"
  }
}

我正在尝试控制台示例来测试与 oracle 自治数据库的连接:

using System;
using Oracle.ManagedDataAccess.Client;

namespace ODP.NET_Core_Autonomous
{
    class Program
    {
        static void Main(string[] args)
        {
            //Demo: ODP.NET Core application that connects to Oracle Autonomous DB

            //Enter user id and password, such as ADMIN user    
            string conString = "User Id=admin;Password=XXXXXXX;" +

            //Enter net service name for data source value
            "Data Source=autonomous;";

            using (OracleConnection con = new OracleConnection(conString))
            {
                using (OracleCommand cmd = con.CreateCommand())
                {
                    try
                    {
                        //Connect descriptor and net service name entry
                        //Enter the database machine port, hostname/IP, service name, and distinguished name
                        OracleConfiguration.OracleDataSources.Add("autonomous", "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-mumbai-1.oraclecloud.com))(connect_data=(service_name=XXXXXXX_webapi_high.atp.oraclecloud.com))(security=(ssl_server_cert_dn=CN=adb.ap-mumbai-1.oraclecloud.com,OU=Oracle ADB INDIA,O=Oracle Corporation,L=Redwood City,ST=California,C=US)))");

                        //Enter directory where wallet is stored locally
                        OracleConfiguration.WalletLocation = @"/home/opc/wallet/Wallet_webapi.zip";

                        con.Open();

                        Console.WriteLine("Successfully connected to Oracle Autonomous Database");

                        //Retrieve database version info
                        cmd.CommandText = "SELECT BANNER FROM V$VERSION";
                        OracleDataReader reader = cmd.ExecuteReader();
                        reader.Read();
                        Console.WriteLine("Connected to " + reader.GetString(0));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    Console.ReadLine();
                }
            }
        }
    }
}

结果: [opc@myhost oratest]$ sudo dotnet run 连接请求超时

现在我想测试与 Oracle Cloud(自治数据库)的连接,如何通过 appsettings.json 配置钱包和连接设置?

【问题讨论】:

    标签: oracle asp.net-core oracle-cloud-infrastructure


    【解决方案1】:

    看看here,它解释了如何配置你的环境,然后链接到示例代码。

    【讨论】:

    • - 对于 NuGet 安装,将内容解压缩到 ASP.NET 应用程序的 Web 应用程序根目录或 Windows 应用程序的 .EXE 目录。它适用于网络核心(centos 7)吗?
    • 在任何应用程序中使用 zip 的方式(除了 sqlcl 和 sqldev)是解压到某个地方,修改包含的 sqlnet.ora 目录,使钱包位置指向你解压的目录,然后让你的应用使用这个目录(例如通过 TNS_ADMIN 环境变量)。这适用于 Windows、macOS 或 Linux 应用程序。
    • 终于我搞定了,net core TNS_ADMIN 不能由 env 变量设置。它可以使用属性 O​​racleConfiguration.TnsAdmin 进行设置。 OracleConfiguration.TnsAdmin = @"/home/opc/wallet"; // 提取钱包的路径。下一步在 appsettings.json 中配置它。
    • @syahman 你好...我目前正在努力自己连接到 oracle。我现在连接字符串失败。在哪个文件中,我应该将部分 webapi 设置为 OracleConfiguration.TnsAdmin 到路径?您能否重现这部分代码?干杯=D
    • @syahman 还有,我该如何配置您在 appsettings.json 中提到的提取路径?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-21
    • 2022-01-08
    • 2023-03-28
    • 1970-01-01
    • 2017-12-15
    相关资源
    最近更新 更多