-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathconfiguration-class.cs
90 lines (73 loc) · 3.42 KB
/
configuration-class.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.ReceiveBufferSize = 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();
}
}
}
}
/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with The MIT
* License (the "License.")
*
* You may obtain a copy of the License at
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*****************************************************************************/