Complete example

2026-03-30 09:33:29  Updated

The following example shows the complete process of connecting to a database, executing SQL statements, and reading the result set by using OceanBase Connector/NET. The API usage is similar to that of Oracle ODP.NET. For more information about how to reference packages, see Reference and use packages.

using Oracle.ManagedDataAccess.Client;

var connectionString = "Data Source=host:port;User Id=username@tenant_name#cluster_name;Password=password;Database=schema_name;";
using var conn = new OracleConnection(connectionString);
conn.Open();

using var cmd = conn.CreateCommand();
cmd.CommandText = "CREATE TABLE test_table(a VARCHAR2(100))";
cmd.ExecuteNonQuery();

cmd.CommandText = "INSERT INTO test_table VALUES(:a)";
cmd.Parameters.Add(new OracleParameter("a", "abc123"));
cmd.ExecuteNonQuery();

cmd.CommandText = "SELECT * FROM test_table";
cmd.Parameters.Clear();
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
    Console.WriteLine("c1=" + reader.GetValue(0).ToString());
}

conn.Close();

Note

For more information about the connection string format, see Connection strings. In Oracle mode, you must specify the Database (schema). For more information about the supported commands and limitations of OracleCommand and OracleDataReader, see Overview of commands and Types of result sets.

Contact Us