1
1
using Oracle . ManagedDataAccess . Client ;
2
+ using System . Threading . Tasks ;
2
3
using System . Threading ;
3
4
using System ;
4
5
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.
6
+ // This app uses synchronous ODP.NET (managed or core) APIs to open a connection,
7
+ // execute a SQL statement, and read the results. It times how long these operations take.
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 19c or higher.
10
+
7
11
8
12
class ODPNET_Sync
9
13
{
10
14
static void Main ( )
11
15
{
12
16
// Add password and data source to connect to your Oracle database
13
- string conString = @ "User Id=hr;Password=<PASSWORD>;Data Source=<NET SERVICE NAME >;";
17
+ string conString = "User Id=hr;Password=<PASSWORD>;Data Source=<DATA SOURCE >;" ;
14
18
15
19
using ( OracleConnection con = new OracleConnection ( conString ) )
16
- {
17
- // Measure time Open takes before next operation can start execution
20
+ {
21
+ //Time how long it takes to open a connection
18
22
DateTime start_time = DateTime . Now ;
19
23
con . Open ( ) ;
20
24
DateTime end_time_open = DateTime . Now ;
@@ -30,35 +34,36 @@ static void Main()
30
34
reader . Read ( ) ;
31
35
}
32
36
}
33
- // Measure time all the sync operations took
34
37
DateTime end_time_all = DateTime . Now ;
35
38
36
- // Calculate connection open time and write result to console
39
+ // Calculate connection open time
37
40
TimeSpan ts_open = end_time_open - start_time ;
38
41
double ts_open1 = Math . Round ( ts_open . TotalSeconds , 2 ) ;
39
42
Console . WriteLine ( "Synchronous connection open time: " + ts_open1 + " seconds" ) ;
40
43
41
- // Calculate overall operation time and write result to console
44
+ // Calculate overall ODP.NET operation time
42
45
TimeSpan ts_all = end_time_all - start_time ;
43
46
double ts_all1 = Math . Round ( ts_all . TotalSeconds , 2 ) ;
44
- Console . WriteLine ( "Synchronous ODP.NET operations time: " + ts_all1 + " seconds" ) ;
47
+ Console . WriteLine ( "Synchronous ODP.NET overall time: " + ts_all1 + " seconds" ) ;
45
48
}
46
49
}
47
50
}
48
51
49
- /* Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. */
52
+ /* Copyright (c) 2023, 2024 Oracle and/or its affiliates. All rights reserved. */
50
53
51
54
/******************************************************************************
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
55
*
56
- * http://www.apache.org/licenses/LICENSE-2.0
56
+ * You may not use the identified files except in compliance with The MIT
57
+ * License (the "License.")
58
+ *
59
+ * You may obtain a copy of the License at
60
+ * https://github.com/oracle/Oracle.NET/blob/master/LICENSE.txt
61
+ *
62
+ * Unless required by applicable law or agreed to in writing, software
63
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
64
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
65
+ *
66
+ * See the License for the specific language governing permissions and
67
+ * limitations under the License.
57
68
*
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
69
*****************************************************************************/
0 commit comments