-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
42 lines (32 loc) · 1.22 KB
/
Program.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
using System;
using Oracle.ManagedDataAccess.Client;
using Dapper;
namespace OracleCore
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Connecting to Oracle...");
using (var conn = new OracleConnection())
{
conn.ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)));User Id=system;Password=oracle;";
conn.Open();
Console.WriteLine("Connected!");
const string sql = "SELECT 1+2 FROM DUAL";
// Using ADO
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
Console.WriteLine("Executing command:");
var result = cmd.ExecuteScalar();
Console.WriteLine($"Result via ADO: {result}");
}
// Using Dapper
var resultDapper = conn.QuerySingle<int>(sql);
Console.WriteLine($"Result via Dapper: {resultDapper}");
}
Console.WriteLine("Done!");
}
}
}