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 74a8d70

Browse files
authored
Create no-pipelining-and-sync.cs (#404)
New synchronous and no pipelining sample
1 parent 5bb48ae commit 74a8d70

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using Oracle.ManagedDataAccess.Client;
2+
using System.Threading.Tasks;
3+
using System.Threading;
4+
using System;
5+
6+
// This code sample demonstrates using synchronous ODP.NET (managed or core) without pipelining.
7+
// It times opening a connection and several query executions.
8+
// To run this app, add your database's HR schema User Id, Password, and Data Source values
9+
// with ODP.NET 23ai or higher connecting to an Oracle Database 23ai or higher.
10+
11+
class ODPNET_Sync_And_No_Pipelining
12+
{
13+
static void Main()
14+
{
15+
// Add password and data source to connect to your Oracle database
16+
string conString = "User Id=hr;Password=<PASSWORD>;Data Source=<DATA SOURCE>;";
17+
18+
using (OracleConnection con = new OracleConnection(conString))
19+
{
20+
string cmdText1 = "SELECT * FROM EMPLOYEES";
21+
string cmdText2 = "SELECT * FROM DEPARTMENTS";
22+
string cmdText3 = "SELECT * FROM JOBS";
23+
24+
OracleCommand cmd1 = new OracleCommand(cmdText1, con);
25+
OracleCommand cmd2 = new OracleCommand(cmdText2, con);
26+
OracleCommand cmd3 = new OracleCommand(cmdText3, con);
27+
28+
// Measure how long connection open takes
29+
DateTime start_time = DateTime.Now;
30+
con.Open();
31+
DateTime end_time_open = DateTime.Now;
32+
33+
// Simulate an operation that takes one second
34+
Thread.Sleep(1000);
35+
36+
// Measure time for query executions
37+
DateTime start_time_query = DateTime.Now;
38+
cmd1.ExecuteNonQuery();
39+
cmd2.ExecuteNonQuery();
40+
cmd3.ExecuteNonQuery();
41+
42+
// Simulate an operation that takes one second
43+
Thread.Sleep(1000);
44+
45+
// Record time all the synchronous operations took plus the sleep time
46+
DateTime end_time_all = DateTime.Now;
47+
48+
// Calculate connection open time
49+
TimeSpan ts_open = end_time_open - start_time;
50+
double ts_open1 = Math.Round(ts_open.TotalSeconds, 2);
51+
Console.WriteLine("Synchronous connection open time: " + ts_open1 + " seconds");
52+
53+
// Calculate SQL executions time
54+
TimeSpan ts_sql = end_time_all - start_time_query;
55+
double ts_sql1 = Math.Round(ts_sql.TotalSeconds, 2);
56+
Console.WriteLine("Synchronous query execution time: " + ts_sql1 + " seconds");
57+
58+
// Calculate overall ODP.NET operation time
59+
TimeSpan ts_all = end_time_all - start_time;
60+
double ts_all1 = Math.Round(ts_all.TotalSeconds, 2);
61+
Console.WriteLine("Synchronous operation total time: " + ts_all1 + " seconds");
62+
63+
cmd1.Dispose();
64+
cmd2.Dispose();
65+
cmd3.Dispose();
66+
}
67+
}
68+
}
69+
70+
/* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. */
71+
72+
/******************************************************************************
73+
*
74+
* You may not use the identified files except in compliance with The MIT
75+
* License (the "License.")
76+
*
77+
* You may obtain a copy of the License at
78+
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
79+
*
80+
* Unless required by applicable law or agreed to in writing, software
81+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
82+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
83+
*
84+
* See the License for the specific language governing permissions and
85+
* limitations under the License.
86+
*
87+
*****************************************************************************/

0 commit comments

Comments
(0)

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