本文整理汇总了C#中System.Data.OracleClient.OracleConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# OracleConnection.Open方法的具体用法?C# OracleConnection.Open怎么用?C# OracleConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.OracleClient.OracleConnection
的用法示例。
在下文中一共展示了OracleConnection.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConnection
// returns a Open connection
public override void GetConnection ()
{
string connectionString = null;
try {
connectionString = ConfigClass.GetElement (configDoc, "database", "connectionString");
} catch (XPathException e) {
Console.WriteLine ("Error reading the config file !!");
Console.WriteLine (e.Message);
return;
}
con = new OracleConnection (connectionString);
try {
con.Open ();
} catch (OracleException e) {
Console.WriteLine ("Cannot establish connection with the database");
Console.WriteLine ("Probably the database is down");
con = null;
} catch (InvalidOperationException e) {
Console.WriteLine ("Cannot open connection");
Console.WriteLine ("Probably the connection is already open");
con = null;
} catch (Exception e) {
Console.WriteLine ("Cannot open connection");
con = null;
}
}
示例2: FillTreeView
public static void FillTreeView(TreeNode node, string sql)
{
try
{
OracleConnection conn = new OracleConnection(DataAccess.OIDSConnStr);
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
node.Nodes.Add(dr[0].ToString());
}
conn.Close();
dr.Close();
}
}
catch (OracleException ox)
{
MessageBox.Show(ox.Message.ToString());
return;
}
}
示例3: run
public void run()
{
Exception exp = null;
OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
con.Open();
OracleCommand cmd = new OracleCommand("Select * From Customers", con);
OracleDataReader rdr = cmd.ExecuteReader();
try
{
BeginCase("Before execute");
Compare(rdr.Depth , 0);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
try
{
BeginCase("After execute");
rdr.Read();
Compare(rdr.Depth , 0);
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
if (con.State == ConnectionState.Open) con.Close();
}
示例4: FillComb
/// <summary>
/// 填充combox
/// </summary>
/// <param name="cb"></param>
/// <param name="sql"></param>
private void FillComb(ComboBox cb,string sql)
{
try
{
OracleConnection conn = new OracleConnection(DataAccess.OIDSConnStr);
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = sql;
OracleDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
cb.Items.Clear();
cb.Items.Add("");
while (dr.Read())
{
cb.Items.Add(dr[0].ToString());
}
conn.Close();
dr.Close();
}
}
catch (OracleException ox)
{
MessageBox.Show(ox.Message.ToString());
return;
}
}
示例5: GetFeature
public static string GetFeature(string p_key, int p_size, int p_page)
{
StringBuilder sb = new StringBuilder();
using (OracleConnection conn = new OracleConnection(OraHelper.str))
{
conn.Open();
OracleCommand comm = conn.CreateCommand();
comm.CommandText = string.Format(SQL_SEARCH_STATION_TOTAL, p_size, p_key);
object total = comm.ExecuteScalar();
comm.CommandText = string.Format(SQL_SEARCH_STATION, p_key, p_page * p_size, (p_page - 1) * p_size);
OracleDataReader rdr = comm.ExecuteReader();
string str = Reader2JSON.ToJSON(rdr);
sb.Append("{\"total\":");
sb.Append(total);
sb.Append(",\"page\":");
sb.Append(p_page);
sb.Append(",\"content\":");
sb.Append(str);
sb.Append("}");
conn.Close();
}
return sb.ToString();
}
示例6: lbuBack_Click
protected void lbuBack_Click(object sender, EventArgs e)
{
PersonnelSystem ps = PersonnelSystem.GetPersonnelSystem(this);
Person loginPerson = ps.LoginPerson;
int count = 0;
using (OracleConnection con = new OracleConnection(DatabaseManager.CONNECTION_STRING)) {
con.Open();
using (OracleCommand com = new OracleCommand("SELECT COUNT(LEAVE_ID) FROM LEV_LEAVE WHERE CMD_HIGH_ID = '" + loginPerson.CitizenID + "' AND LEV_LEAVE.STATE_ID = 3", con)) {
using (OracleDataReader reader = com.ExecuteReader()) {
while (reader.Read()) {
count = int.Parse(reader.GetValue(0).ToString());
}
}
}
}
if (count == 0) {
error_area.InnerHtml = "ไม่มีรายการที่ท่านต้องอนุมัติ";
} else {
error_area.InnerHtml = "กรุณาเลือกรายการที่ต้องอนุมัติ";
}
//error_area.Attributes["class"] = "alert alert_info";
error_area.Attributes["class"] = null;
error_area.InnerHtml = "";
MultiView1.ActiveViewIndex = 0;
}
示例7: run
public void run()
{
Exception exp = null;
OracleConnection con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
con.Open();
OracleCommand cmd = new OracleCommand("Select * From Orders", con);
OracleDataReader rdr = cmd.ExecuteReader();
//change a connection's state without closing the datareader (should fail
try
{
BeginCase("InvalidOperationException");
try
{
((IDbConnection)con).ChangeDatabase("msdb");
ExpectedExceptionNotCaught(typeof(InvalidOperationException).FullName);
}
catch (InvalidOperationException ex)
{
ExpectedExceptionCaught(ex);
}
}
catch(Exception ex){exp = ex;}
finally{EndCase(exp); exp = null;}
if (con.State == ConnectionState.Open) con.Close();
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string guid = string.Empty;
guid = Request["q"];
int ww = Convert.ToInt32(Request["w"]);
int wh = Convert.ToInt32(Request["h"]);
if (guid == null || guid == string.Empty)
{
this.map.InnerHtml = "<h1 style='font-size:24px;text-align:center;'>输入参数无效</h1>";
Response.End();
}
else
{
using (OracleConnection conn = new OracleConnection(OraHelper.str))
{
conn.Open();
OracleCommand comm = conn.CreateCommand();
comm.CommandText = string.Format(SQL_SELECT, guid);
OracleDataReader dr = comm.ExecuteReader();
if (dr.Read())
{
string innerHTML = dr["DATA"].ToString();
this.map.InnerHtml = innerHTML;
this.map.Style.Value = "display:block;width:" + ww + "px;height:" + wh + "px;";
}
else
{
this.map.InnerHtml = "<h1 style='font-size:24px;text-align:center;'>该分享不存在</h1>";
}
}
}
}
示例9: EditFeature
public static bool EditFeature(string labelid,string title,string content)
{
StringBuilder sb = new StringBuilder();
using (OracleConnection conn = new OracleConnection(OraHelper.str))
{
conn.Open();
OracleCommand comm = conn.CreateCommand();
OracleParameter[] parms = new OracleParameter[]{
new OracleParameter(":LABELID",OracleType.VarChar),
new OracleParameter(":TITLE",OracleType.VarChar),
new OracleParameter(":CONTENT",OracleType.VarChar)
};
parms[0].Value = labelid;
parms[1].Value = title;
parms[2].Value = content;
comm.CommandText = SQL_UPDATE_LABEL;
comm.CommandType = CommandType.Text;
foreach (OracleParameter parm in parms)
{
comm.Parameters.Add(parm);
}
comm.ExecuteNonQuery();
conn.Close();
return true;
}
}
示例10: CheckDPISConnect
public static string CheckDPISConnect()
{
string ret = "false";
string connStr = DPISConnectionString;
OracleConnection conn = new OracleConnection(connStr);
try
{
conn.Open();
string ServerName = conn.DataSource;
string DbName = conn.Database;
ret = "true|ServerName = " + ServerName + "&DatabaseName=" + DbName;
}
catch (Exception ex)
{
ret = "false|Exception " + ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine;
ret += "ConnectionString = " + connStr;
}
finally
{
conn.Close();
conn.Dispose();
}
return ret;
}
示例11: button1_Click
private void button1_Click(object sender, EventArgs e)
{
//||
if (nomseq == "")
{
MessageBox.Show("NOMBRE DE SECUENCIA INVALIDO" + nomseq, "PROYECTO TDB1", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
string query = "create sequence\"" + nomseq + "\"" + " start with " + empieza_con + " maxvalue " + valor_max + " minvalue " + valor_min +"\n"+ cache +"\n"+ cycle +"\n"+ order;
// string query = nomseq +" "+ empieza_con +" "+ valor_max +" "+ valor_min +" "+ aumenta_por +" "+ cache +" "+ cycle+" " + order;
MessageBox.Show(query);
OracleConnection con = new OracleConnection("Data Source= XE; User Id=" + Form1.user + "; Password=" + Form1.pass + ";");
con.Open();
OracleCommand cmd = new OracleCommand(query, con);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Se ha Creado la Secuencia "+nomseq,"PROYECTO TDB1",MessageBoxButtons.OK,MessageBoxIcon.Information);
cmb_nomsec.Items.Clear();
cmb_nomsec2.Items.Clear();
CARGAR_SECUENCIAS();
}catch(Exception err){
MessageBox.Show("ERROR: " + err.Message.ToString(), "PROYECTO TDB1", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
示例12: PrepareCommand
/// <summary>
/// This method opens (if necessary) and assigns a connection, transaction, command type and parameters
/// to the provided command.
/// </summary>
/// <param name="command">the OracleCommand to be prepared</param>
/// <param name="connection">a valid OracleConnection, on which to execute this command</param>
/// <param name="transaction">a valid OracleTransaction, or 'null'</param>
/// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
/// <param name="commandText">the stored procedure name or PL/SQL command</param>
/// <param name="commandParameters">an array of OracleParameters to be associated with the command or 'null' if no parameters are required</param>
private static void PrepareCommand(OracleCommand command, OracleConnection connection, OracleTransaction transaction, CommandType commandType, string commandText, OracleParameter[] commandParameters)
{
//if the provided connection is not open, we will open it
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
//associate the connection with the command
command.Connection = connection;
//set the command text (stored procedure name or Oracle statement)
command.CommandText = commandText;
command.CommandTimeout = 200000;
//if we were provided a transaction, assign it.
if (transaction != null)
{
command.Transaction = transaction;
}
//set the command type
command.CommandType = commandType;
//attach the command parameters if they are provided
if (commandParameters != null)
{
AttachParameters(command, commandParameters);
}
return;
}
示例13: GV_RowUpdating
protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
using (OracleConnection conn = new OracleConnection(DBHelper.ConnectionString))
{
string reason_id = GV.DataKeys[e.RowIndex].Values[0].ToString();
string reason_desc = ((TextBox)GV.Rows[e.RowIndex].FindControl("TxtDesc")).Text;
string active = ((CheckBox)(GV.Rows[e.RowIndex].FindControl("ChkActive"))).Checked == true ? "1" : "0";
string sqlupdate = "update jp_lack_reason set reason_desc = '" + reason_desc + "',is_valid='" + active + "' where reason_id = '" + reason_id + "' ";
OracleCommand updatecomm = new OracleCommand(sqlupdate, conn);
try
{
conn.Open();
updatecomm.ExecuteNonQuery();
GV.EditIndex = -1;
GVDataBind();
}
catch (Exception ex)
{
conn.Close();
Response.Write("<script language=javascript>alert('" + ex.Message + "')</script>");
}
finally
{
updatecomm.Dispose();
conn.Dispose();
conn.Close();
}
}
}
示例14: UpdateExcelInfo
/// <summary>
/// 将生成的材料信息更新到数据库中
/// </summary>
/// <param name="sql"></param>
/// <param name="excelinfo"></param>
public static void UpdateExcelInfo(string sql,byte[] excelinfo)
{
try
{
byte[] file = excelinfo;
using (OracleConnection conn = new OracleConnection(DataAccess.OIDSConnStr))
{
conn.Open();
using (OracleCommand cmd = conn.CreateCommand())
{
cmd.CommandText = sql;
OracleParameter op = new OracleParameter("dfd", OracleType.Blob);
op.Value = file;
if (file.Length == 0)
{
MessageBox.Show("插入信息表不能为空!", "WARNNING", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return;
}
else
{
cmd.Parameters.Add(op);
cmd.ExecuteNonQuery();
}
}
conn.Close();
}
}
catch (IOException ee)
{
MessageBox.Show(ee.Message.ToString());
return;
}
}
示例15: showDonVi
protected void showDonVi()
{
try
{
string user = "CMIS01PC1";
string dataSource = showSiteName();
if (dataSource.ToUpper() == "BACGIANG")
user = "CMIS01PCBG";
string txt_cmd = string.Format("Data Source={0}; User ID={1}; Password={1}; Unicode=True", dataSource, user);
if (dataSource.ToUpper() == "NGHEAN")
txt_cmd = string.Format("Data Source={0}; User ID={1}; Password={2}; Unicode=True", dataSource, "CMIS01PC1", "PC1CMIS01");
if (dataSource.ToUpper() == "NINHBINH")
txt_cmd = string.Format("Data Source={0}; User ID={1}; Password={2}; Unicode=True", dataSource, "CMIS01PC1", "pc1cmis01");
OracleConnection ora_con = new OracleConnection(txt_cmd);
txt_cmd = "select MA_DVIQLY, TEN_DVIQLY from cmis01.d_dvi_qly where CAP_DVI=3 order by MA_DVIQLY";
OracleDataAdapter ora_da = new OracleDataAdapter(txt_cmd, ora_con);
DataSet ds = new DataSet();
ora_con.Open();
ora_da.Fill(ds);
ora_con.Close();
ddDonViQL.DataSource = ds;
ddDonViQL.DataBind();
}
catch (Exception ex) { lbError.Text = ex.Message; }
}