C # connect to the Oracle database

Source: Internet
Author: User
Tags oracleconnection

Using System;
Using System. Configuration;
Using System. Data;
Using System. Data. OracleClient;
Using System. Collections;
Using System. Web;
Namespace Game. DBUtility
{

/// <Summary>
/// A helper class used to execute queries against an Oracle database
/// A class used to help perform Oracle Database Operations
/// </Summary>
Public abstract class OracleHelper
{

// Read the connection strings from the configuration file
// Read the database connection string from the configuration file
Public static readonly string ConnectionString = ConfigurationManager. ConnectionStrings ["ConnectionString"]. ConnectionString;
Public static readonly string ConnectionStringLocalTransaction = ConfigurationManager. deleettings ["OraConnString1"];
Public static readonly string ConnectionStringInventoryDistributedTransaction = ConfigurationManager. deleettings ["OraConnString2"];
Public static readonly string ConnectionStringOrderDistributedTransaction = ConfigurationManager. deleettings ["OraConnString3"];
Public static readonly string ConnectionStringProfile = ConfigurationManager. deleettings ["OraProfileConnString"];
Public static readonly string ConnectionStringMembership = ConfigurationManager. deleettings ["OraMembershipConnString"];

// Create a hashtable for the parameter cached
// Create a cache for the HA table for Parameter
Private static Hashtable parmCache = Hashtable. Synchronized (new Hashtable ());

/// <Summary>
/// Execute a database query which does not include a select
/// Execute a database operation but does not include a query
/// </Summary>
/// The following parameters are passed.
/// <Param name = "connString"> Connection string to database </param> // Connection string of the database
/// <Param name = "partition type"> Command type either stored procedure or SQL </param> // The Command type is stored procedure or SQL statement.
/// <Param name = "plain text"> Acutall SQL Command </param>
/// <Param name = "commandParameters"> Parameters to bind to the command </param> Parameter
/// <Returns> </returns>
Public static int ExecuteNonQuery (string connectionString, CommandType parameter type, string parameter text, params OracleParameter [] commandParameters)
{
// Create a new Oracle command
// Create an Oracle command object
OracleCommand cmd = new OracleCommand ();

// Create a connection
// Create a connection object
Using (OracleConnection connection = new OracleConnection (connectionString ))
{

// Prepare the command
// Prepare for command. This method is defined below
PrepareCommand (cmd, connection, null, argument type, plain text, commandParameters );

// Execute the command
// Execute command
Int val = cmd. ExecuteNonQuery ();
Cmd. Parameters. Clear ();
Return val;
}
}

/// <Summary>
/// Execute an OracleCommand (that returns no resultset) against an existing database transaction
/// Using the provided parameters.
/// Use parameters to execute existing database transactions (no return value ??) --- Incorrect estimation
/// </Summary>
/// <Remarks>
/// E.g .:
/// Int result = ExecuteNonQuery (trans, CommandType. StoredProcedure, "PublishOrders", new parameter (": prodid", 24 ));
/// Example
/// </Remarks>
/// <Param name = "trans"> an existing database transaction </param> // an existing database transaction
/// <Param name = "commandType"> the CommandType (stored procedure, text, etc.) </param> // command object type (stored procedure ???, Text, others)
/// <Param name = "commandText"> the stored procedure name or PL/SQL command </param> // the stored procedure name or SQL statement
/// <Param name = "commandParameters"> an array of OracleParamters used to execute the command </param> // the Paramter array used for execution
/// <Returns> an int representing the number of rows affected by the command </returns> // the number of rows affected by the command is returned.
Public static int ExecuteNonQuery (OracleTransaction trans, CommandType primitive type, string plain text, params OracleParameter [] commandParameters)
{
OracleCommand cmd = new OracleCommand ();

PrepareCommand (cmd, trans. Connection, trans, argument type, plain text, commandParameters );
Int val = cmd. ExecuteNonQuery ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.