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ディレクトリ設定