-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathDataSourceCollection-class.cs
80 lines (65 loc) · 2.95 KB
/
DataSourceCollection-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
using System;
using Oracle.ManagedDataAccess.Client;
namespace NetCoreApp
{
class DataSourcesExample
{
static void Main(string[] args)
{
// Example to configure Data Sources for the ODP.NET Core provider.
// Add data source through Add method on OracleDataSourceCollection
OracleConfiguration.OracleDataSources.Add("orcl1", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname>)(PORT=1234))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))");
// Add data source through indexer method on OracleDataSourceCollection
OracleConfiguration.OracleDataSources["orcl2"] = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname>)(PORT=1234))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))";
// Get number of data sources configured
int numDataSources = OracleConfiguration.OracleDataSources.Count;
// Get OracleDataSourceCollection object
OracleDataSourceCollection dsColl = OracleConfiguration.OracleDataSources;
// Add server through Add method on OracleDataSourceCollection
dsColl.Add("orcl3", "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname>)(PORT=1234))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))");
// Add server through indexer method on OracleDataSourceCollection
dsColl["orcl4"] = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname>)(PORT=1234))(CONNECT_DATA=(SERVICE_NAME=<service name>)(SERVER=dedicated)))";
// Remove a data source
OracleConfiguration.OracleDataSources.Remove("db2");
// Get number of data sources configured
numDataSources = OracleConfiguration.OracleDataSources.Count;
// Get value corresponding to a data source.
string dsVal = OracleConfiguration.OracleDataSources["db1"];
OracleConnection orclCon = null;
try
{
// Open a test connection
orclCon = new OracleConnection("user id=hr; password=<password>; data source=orcl3");
orclCon.Open();
orclCon.Close();
}
catch (OracleException ex)
{
Console.WriteLine(ex);
}
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.
*
*****************************************************************************/