Skip to content

Commit 18f1200

Browse files
authored
Create sync-odpnet.cs
1 parent 5be652c commit 18f1200

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using Oracle.ManagedDataAccess.Client;
2+
3+
// This app measures how long it takes synchronous ODP.NET operations.
4+
class ODPNET_Sync
5+
{
6+
static void Main()
7+
{
8+
// Modify User Id, Password, and Data Source as needed to connect
9+
string conString = "User Id=hr;Password=<PASSWORD>;Data Source=<DATA SOURCE>;";
10+
11+
using (OracleConnection con = new OracleConnection(conString))
12+
{
13+
DateTime start_time = DateTime.Now;
14+
con.Open();
15+
DateTime end_time_open = DateTime.Now;
16+
17+
// Simulate operation that takes one second
18+
Thread.Sleep(1000);
19+
20+
string cmdText = "SELECT * FROM EMPLOYEES FETCH FIRST 1 ROWS ONLY";
21+
using (OracleCommand cmd = new OracleCommand(cmdText, con))
22+
{
23+
using (OracleDataReader reader = cmd.ExecuteReader())
24+
{
25+
reader.Read();
26+
}
27+
}
28+
DateTime end_time_all = DateTime.Now;
29+
30+
// Calculate connection open time
31+
TimeSpan ts_open = end_time_open - start_time;
32+
double ts_open1 = Math.Round(ts_open.TotalSeconds, 2);
33+
Console.WriteLine("Synchronous connection open time: " + ts_open1 + " seconds");
34+
35+
// Calculate overall operation time
36+
TimeSpan ts_all = end_time_all - start_time;
37+
double ts_all1 = Math.Round(ts_all.TotalSeconds, 2);
38+
Console.WriteLine("Synchronous ODP.NET operations time: " + ts_all1 + " seconds");
39+
}
40+
}
41+
}
42+
43+
44+
/* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. */
45+
46+
/******************************************************************************
47+
*
48+
* You may not use the identified files except in compliance with The MIT
49+
* License (the "License.")
50+
*
51+
* You may obtain a copy of the License at
52+
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
53+
*
54+
* Unless required by applicable law or agreed to in writing, software
55+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
56+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57+
*
58+
* See the License for the specific language governing permissions and
59+
* limitations under the License.
60+
*
61+
*****************************************************************************/

0 commit comments

Comments
 (0)