Oracle Data Provider for .NET Coreの構成
ODP.NET Core開発者は、.NET構成API、sqlnet.ora
ファイルおよびtnsnames.ora
ファイルでアプリケーション設定を割り当てることができます。
.NET構成API
.NET Coreは、.NET構成ファイル(web.config
)を介したアプリケーション構成をサポートしていません。構成ファイルのかわりに.NET構成APIを使用します。ODP.NET Coreは、アプリケーション・レベルのプロバイダ設定用の静的クラスOracleConfiguration
を介して構成APIをサポートしています。OracleDataSourceCollection
クラスは、ネット・サービス名(TNSエントリ)の追加および削除をサポートしています。OracleOnsServerCollection
クラスは、Oracle Notification Service (ONS)デーモンがリモート・クライアントと通信しているノードのリストへの追加および削除をサポートしています。
OracleConfiguration
のすべての構成設定は、アプリケーションで接続を開く前に行う必要があります。接続を開くと、構成プロパティに対する更新によってInvalidOperationException
が発生します。ただし、アプリケーション実行時に引き続き変更できるトレース設定以外の場合のみです。
例2-6 サンプル・コード
using System; using Oracle.ManagedDataAccess.Client; namespace ODP_Core_Config_API { class odp_core_config { static void Main(string[] args) { // This sample demonstrates how to use ODP.NET Core Configuration API // Add connect descriptors and net service names entries. OracleConfiguration.OracleDataSources.Add("orclpdb", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname or IP>)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))"); OracleConfiguration.OracleDataSources.Add("orcl", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname or IP>)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))"); // Set default statement cache size to be used by all connections. OracleConfiguration.StatementCacheSize = 25; // Disable self tuning by default. OracleConfiguration.SelfTuning = false; // Bind all parameters by name. OracleConfiguration.BindByName = true; // Set default timeout to 60 seconds. OracleConfiguration.CommandTimeout = 60; // Set default fetch size as 1 MB. OracleConfiguration.FetchSize = 1024 * 1024; // Set tracing options OracleConfiguration.TraceOption = 1; OracleConfiguration.TraceFileLocation = @"D:\traces"; // Uncomment below to generate trace files //OracleConfiguration.TraceLevel = 7; // Set network properties OracleConfiguration.SendBufferSize = 8192; OracleConfiguration.ReceiveBuffereSize = 8192; OracleConfiguration.DisableOOB = true; OracleConnection orclCon = null; try { // Open a connection orclCon = new OracleConnection("user id=hr; password=<password>; data source=orclpdb"); orclCon.Open(); // Execute simple select statement that returns first 10 names from EMPLOYEES table OracleCommand orclCmd = orclCon.CreateCommand(); orclCmd.CommandText = "select first_name from employees where rownum <= 10 "; OracleDataReader rdr = orclCmd.ExecuteReader(); while (rdr.Read()) Console.WriteLine("Employee Name: " + rdr.GetString(0)); Console.ReadLine(); rdr.Dispose(); orclCmd.Dispose(); } finally { // Close the connection if (null != orclCon) orclCon.Close(); } } } }
Oracleの構成ファイル
ODP.NET Coreでは、次のsqlnet.ora
およびtnsnames.ora
パラメータがサポートされています。これらの設定は、.NET構成APIと組み合せて使用できます。
-
BindByName
-
DbNotificationPort
-
Disable_Oob
–sqlnet.ora
-
DRCPConnectionClass
-
FetchSize
-
MaxStatementCacheSize
-
NAMES.DIRECTORY_PATH
–sqlnet.ora
-
NODELAY
–sqlnet.ora
-
RETRY_COUNT
-
RETRY_DELAY
-
RECEIVE_BUF_SIZE
–sqlnet.ora
またはtnsnames.ora
-
SelfTuning
-
SEND_BUF_SIZE
–sqlnet.ora
またはtnsnames.ora
-
ServiceRelocationConnectionTimeout
-
SQLNET.AUTHENTICATION_SERVICES
–sqlnet.ora
-
SQLNET.CRYPTO_CHECKSUM_CLIENT
–sqlnet.ora
-
SQLNET.CRYPTO_CHECKSUM_TYPES_CLIENT
–sqlnet.ora
-
StatementCacheSize
-
SSL_SERVER_DN_MATCH
–sqlnet.ora
-
SSL_VERSION
–sqlnet.ora
-
TNS_ADMIN
-
TraceFileLocation
-
TraceLevel
-
TraceOption
-
TCP.CONNECT_TIMEOUT
–sqlnet.ora
-
SQLNET.ENCRYPTION_CLIENT
–sqlnet.ora
-
SQLNET.ENCRYPTION_TYPES_CLIENT
–sqlnet.ora
ODP.NET Coreは、sqlnet.ora
およびtnsnames.ora
ファイルを次の優先順位で検索します。
-
OracleConfiguration.OracleDataSources
-
OracleConnection.TnsAdmin
プロパティで設定されたディレクトリ -
Tns_Admin
接続文字列属性用に設定されたディレクトリ -
OracleConfiguration.TnsAdmin
プロパティで設定されたディレクトリ -
現行作業ディレクトリ
-
OS環境変数またはコンテナ環境変数の
TNS_ADMIN
ディレクトリ設定
ODP.NET Coreは、次の優先順位でldap.ora
ファイルを検索します。
-
OracleConnection.TnsAdmin
に設定されたディレクトリ -
Tns_Admin
接続文字列属性用に設定されたディレクトリ -
OracleConfiguration.TnsAdmin
プロパティで設定されたディレクトリ -
OracleConfiguration.LdapAdmin
プロパティに設定されたディレクトリ -
現行作業ディレクトリ
-
環境の
TNS_ADMIN
ディレクトリ設定 -
環境の
LDAP_ADMIN
ディレクトリ設定