Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dd72b07

Browse files
authored
Create sync.cs (#320)
1 parent 7a6b941 commit dd72b07

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

‎samples/async/sync.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using Oracle.ManagedDataAccess.Client;
2+
using System.Threading;
3+
using System;
4+
5+
// This code sample demonstrates using synchronous ODP.NET (managed or core) and times its execution time.
6+
// This sample uses the Oracle HR sample schema.
7+
8+
class ODPNET_Sync
9+
{
10+
static void Main()
11+
{
12+
// Add password and data source to connect to your Oracle database
13+
string conString = @"User Id=hr;Password=<PASSWORD>;Data Source=<NET SERVICE NAME>;";
14+
15+
using (OracleConnection con = new OracleConnection(conString))
16+
{
17+
// Measure time Open takes before next operation can start execution
18+
DateTime start_time = DateTime.Now;
19+
con.Open();
20+
DateTime end_time_open = DateTime.Now;
21+
22+
// Simulate operation that takes one second
23+
Thread.Sleep(1000);
24+
25+
string cmdText = "SELECT * FROM EMPLOYEES FETCH FIRST 100 ROWS ONLY";
26+
using (OracleCommand cmd = new OracleCommand(cmdText, con))
27+
{
28+
using (OracleDataReader reader = cmd.ExecuteReader())
29+
{
30+
reader.Read();
31+
}
32+
}
33+
// Measure time all the sync operations took
34+
DateTime end_time_all = DateTime.Now;
35+
36+
// Calculate connection open time and write result to console
37+
TimeSpan ts_open = end_time_open - start_time;
38+
double ts_open1 = Math.Round(ts_open.TotalSeconds, 2);
39+
Console.WriteLine("Synchronous connection open time: " + ts_open1 + " seconds");
40+
41+
// Calculate overall operation time and write result to console
42+
TimeSpan ts_all = end_time_all - start_time;
43+
double ts_all1 = Math.Round(ts_all.TotalSeconds, 2);
44+
Console.WriteLine("Synchronous ODP.NET operations time: " + ts_all1 + " seconds");
45+
}
46+
}
47+
}
48+
49+
/* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. */
50+
51+
/******************************************************************************
52+
* Licensed under the Apache License, Version 2.0 (the "License");
53+
* you may not use this file except in compliance with the License.
54+
* You may obtain a copy of the License at
55+
*
56+
* http://www.apache.org/licenses/LICENSE-2.0
57+
*
58+
* Unless required by applicable law or agreed to in writing, software
59+
* distributed under the License is distributed on an "AS IS" BASIS,
60+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
61+
* See the License for the specific language governing permissions and
62+
* limitations under the License.
63+
*
64+
*****************************************************************************/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /