- Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathAppContinuity.cs
107 lines (94 loc) · 4.73 KB
/
AppContinuity.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
usingSystem;
usingSystem.Threading;
usingSystem.Transactions;
//using Oracle.DataAccess.Client;
usingOracle.ManagedDataAccess.Client;
namespaceAppContinuity
{
classProgram
{
staticvoidMain(string[]args)
{
//Demo: ODP.NET Application Continuity
//Demonstrates that applications can recover and continue after
// recoverable errors without end user disruption. Recoverable errors
// are errors that arise due to an external system failure,
// independent of the application session logic that is executing.
// Recoverable errors occur following planned and unplanned outages
// of foregrounds, networks, nodes, storage, and databases, such as a
// network outage, instance failure, hardware failure, network failure,
// configuration change, or patching.
//To use Application Continuity with ODP.NET, set
// Application Continuity=true (default) in the connection string.
//Setup instructions:
// A) On the database server :
// 1) Setup HR schema by using script %ORACLE_HOME%\demo\schema\human_resources\hr_main.sql
// if not already available.
// 2) Run "GRANT execute on DBMS_APP_CONT to HR;" so that ODP.NET can determine the
// in-flight transaction status following a recoverable error.
// B) In client app, modify the following connection attributes in this sample code:
// 1) Password: Password you specified while setting up HR schema setup.
// 2) Data Source: Connection descriptor or TNS alias to connect to the database.
// 3) Use the Oracle.ManagedDataAccess.Client namespace for managed ODP.NET or ODP.NET Core.
// Or use Oracle.Data.Client namespace for unmanaged ODP.NET.
// Be sure to use a minimum version of ODP.NET Core 23c, managed ODP.NET 23c, or unmanaged ODP.NET 12.2 for AC support.
//Runtime instructions:
// You can intermittently execute the following command on the database
// to simulate a recoverable error condition and observe AC in action:
// "Execute dbms_service.disconnect_session('your service', dbms_service.immediate );"
//
// With Application Continuity enabled, the end user will observe
// no error message, only a slight delayed execution.
//Provide user id and password for Oracle user
stringconString="User Id=hr;Password=<password>;"+
//Provide Oracle data source info.
"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=<hostname or IP>)(PORT=<port>))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=<service name>)));";
//Loop infinitely
while(true)
{
try
{
using(OracleConnectioncon=newOracleConnection(conString))
{
using(OracleCommandcmd=con.CreateCommand())
{
//Start transaction
using(TransactionScopescope=newTransactionScope())
{
con.Open();
cmd.CommandText="update employees set salary=salary+1 where employee_id = 100";
cmd.ExecuteNonQuery();
//Commit
scope.Complete();
Console.WriteLine("Salary incremented.");
}
//Sleep for 1 second
Thread.Sleep(1000);
}
}
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}
/* Copyright (c) 2019, 2023 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.
*
*****************************************************************************/