Exemplo n.º 1
0
 /// <summary>
 /// 关闭连接
 /// </summary>
 public void ConnectionClose()
 {
     if (_conn.State == ConnectionState.Open)
     {
         _conn.Close();
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            /*
             * Traditional TNS Definition
             * ORA11G =
             * (DESCRIPTION =
             * (ADDRESS = (PROTOCOL = TCP)(HOST = ora11g-win.windsor.com)(PORT = 1521))
             * (CONNECT_DATA =
             * (SERVER = DEDICATED)
             * (SID = ora11g)
             * )
             * )
             *
             * .Net Connection String information:
             * "user id=NV_NSITE_DEV;password=memorial;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11g-win.windsor.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ora11g)))"
             *
             * Easy Connect Naming version (standard):
             * "User Id=NV_NSITE_DEV;password=memorial;Data Source=host[port - default 1521][/servicename]"
             *
             * Easy Connect Naming version (dedicated server):
             * "User Id=NV_NSITE_DEV;password=memorial;Data Source=ora11g-win.windsor.com/ora11g:dedicated"
             *
             */
            string connectionString = "user id=NV_NSITE_DEV;password=memorial;data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora11g-win.windsor.com)(PORT=1521))(CONNECT_DATA=(SERVICER=DEDICATED)(SID=ora11g)))";

            //string connectionString = "Data Source=NV_NSITE_DEV/[email protected]:1521/ora11g";

            Console.WriteLine("Connecting with System.Data.OracleClient");
#pragma warning disable 618
            using (var connection = new System.Data.OracleClient.OracleConnection(connectionString))
#pragma warning restore 618
            {
                try
                {
                    connection.Open();
                    Console.WriteLine("Connection Successful using System.Data.OracleClient (deprecated)");
                    connection.Close();
                }
                catch (OracleException ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            Console.WriteLine("Connecting with Oracle.DataAccess.Client.OracleConnection");
            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                try
                {
                    connection.Open();
                    Console.WriteLine("Connection Successful using Oracle.DataAccess");
                    connection.Close();
                }
                catch (OracleException ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }
Exemplo n.º 3
0
        private void bOK_Click(object sender, EventArgs e)
        {
            string strServer, strUser, strPassword;
            string Return_Value;

            System.Data.OracleClient.OracleConnection con = new System.Data.OracleClient.OracleConnection();

            strServer   = textBoxServer.Text;
            strUser     = textBoxLog.Text;
            strPassword = textBoxPass.Text;

            Return_Value = INIExists(inifile);
            if (!String.IsNullOrEmpty(Return_Value))
            {
                MessageBox.Show(Return_Value);
                return;
            }
            string connStr = "Data Source=" + strServer + ";User Id=" + strUser + ";Password="******";Integrated Security=no;";

            con.ConnectionString = connStr;
            try
            {
                con.Open();
            }
            catch (Exception ex)
            {
                con.Close();
                MessageBox.Show("数据库连接失败!" + ex.Message, "仪器数据接收", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            strServer   = EncryptDES(strServer, "zlsofthis");
            strUser     = EncryptDES(strUser, "zlsofthis");
            strPassword = EncryptDES(strPassword, "zlsofthis");

            long OpStation = WritePrivateProfileString("EQUIPMENT", "DBSERVER", strServer, System.AppDomain.CurrentDomain.BaseDirectory.ToString() + inifile);

            if (OpStation == 0)
            {
                MessageBox.Show("未找到段落【EQUIPMENT】或关键字【DBSERVER】!");
            }
            OpStation = WritePrivateProfileString("EQUIPMENT", "LOGID", strUser, System.AppDomain.CurrentDomain.BaseDirectory.ToString() + inifile);
            if (OpStation == 0)
            {
                MessageBox.Show("未找到段落【EQUIPMENT】或关键字【LOGID】!");
            }
            OpStation = WritePrivateProfileString("EQUIPMENT", "LOGPASS", strPassword, System.AppDomain.CurrentDomain.BaseDirectory.ToString() + inifile);
            if (OpStation == 0)
            {
                MessageBox.Show("未找到段落【EQUIPMENT】或关键字【LOGPASS】!");
            }
            this.DialogResult = DialogResult.OK;
        }
Exemplo n.º 4
0
        //Connection to Oracle database
        public System.Data.DataTable OracOLEds(string SqlString, string constring, int rowlimit)
        {
            DataTable dt = new DataTable();

            if (rowlimit > 0)
            {
                try
                {
                    using (System.Data.OracleClient.OracleConnection OracConnect = new System.Data.OracleClient.OracleConnection(constring))
                    {
                        OracConnect.Open();
                        System.Data.OracleClient.OracleCommand    OraCmd     = new System.Data.OracleClient.OracleCommand(SqlString, OracConnect);
                        System.Data.OracleClient.OracleDataReader Oraxreader = OraCmd.ExecuteReader();
                        DataSet ds = new DataSet();
                        ds.Load(Oraxreader, LoadOption.OverwriteChanges, "Result");
                        var ddt = ds.Tables[0].AsEnumerable().Take(rowlimit);
                        dt = ddt.CopyToDataTable <DataRow>();
                        Oraxreader.Close();
                        OracConnect.Close();
                    }
                }
                catch (Exception exOrac)
                {
                    var ex1 = exOrac.Message;
                }
            }
            else
            {
                try
                {
                    using (System.Data.OracleClient.OracleConnection OracConnect = new System.Data.OracleClient.OracleConnection(constring))
                    {
                        OracConnect.Open();
                        System.Data.OracleClient.OracleCommand    OraCmd     = new System.Data.OracleClient.OracleCommand(SqlString, OracConnect);
                        System.Data.OracleClient.OracleDataReader Oraxreader = OraCmd.ExecuteReader();
                        DataSet ds = new DataSet();
                        ds.Load(Oraxreader, LoadOption.OverwriteChanges, "Result");
                        dt = ds.Tables[0];
                        Oraxreader.Close();
                        OracConnect.Close();
                    }
                }
                catch (Exception exOrac)
                {
                    var ex1 = exOrac.Message;
                }
            }
            return(dt);
        }
Exemplo n.º 5
0
 public void Login_Load(object sender, EventArgs e)
 {
     System.Data.OracleClient.OracleConnection con = new System.Data.OracleClient.OracleConnection();
     con.ConnectionString = OracleHelper.GetConnectionstring();
     try
     {
         con.Open();
     }
     catch (Exception ex)
     {
         con.Close();
         return;
     }
     this.DialogResult = DialogResult.OK;
 }
Exemplo n.º 6
0
        protected void GrdViewDocs_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                GridDataItem dataitem = e.Item as GridDataItem;

                //DataTable dtcon = CM_Main.SelectJob("CASE11", dataitem["REQUEST_ID"].Text, "", "", "", "", System.DateTime.Now);
                //grdRequest.DataSource = dtcon;
                //grdRequest.DataBind();

                //  int idx = dataitem["REQUEST_ID"].Text;

                // Label lbl = dataitem["ID"].Text;

                System.Data.OracleClient.OracleConnection conn      = new System.Data.OracleClient.OracleConnection(ConfigurationManager.ConnectionStrings["CGConnectionString"].ToString());
                System.Data.OracleClient.OracleCommand    myCommand = new System.Data.OracleClient.OracleCommand("SELECT * FROM wf_cm_docs_jobwise_blob WHERE ID = '" + dataitem["ID"].Text + "'", conn);
                conn.Open();
                System.Data.OracleClient.OracleDataReader myReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default);
                try
                {
                    while (myReader.Read())
                    {
                        System.Data.OracleClient.OracleLob myLob = myReader.GetOracleLob(myReader.GetOrdinal("DOCUMENT"));
                        if (!myLob.IsNull)
                        {
                            string FN = myReader.GetString(myReader.GetOrdinal("DOCUMENT_NAME"));


                            //Use buffer to transfer data
                            byte[] b = new byte[myLob.Length];
                            //Read data from database
                            myLob.Read(b, 0, (int)myLob.Length);


                            Response.AddHeader("content-disposition", "attachment;filename=" + FN);
                            Response.ContentType = "application/octectstream";
                            Response.BinaryWrite(b);
                            Response.End();
                        }
                    }
                }
                finally
                {
                    myReader.Close();
                    conn.Close();
                }
            }
        }
Exemplo n.º 7
0
        protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = DataList2.SelectedIndex;

            Label lbl = (Label)DataList2.Items[idx].FindControl("Label2");

            System.Data.OracleClient.OracleConnection conn      = new System.Data.OracleClient.OracleConnection(ConfigurationManager.ConnectionStrings["CGConnectionString"].ToString());
            System.Data.OracleClient.OracleCommand    myCommand = new System.Data.OracleClient.OracleCommand("SELECT * FROM wf_it_images WHERE ID = '" + lbl.Text + "'", conn);
            conn.Open();
            System.Data.OracleClient.OracleDataReader myReader = myCommand.ExecuteReader(System.Data.CommandBehavior.Default);
            try
            {
                while (myReader.Read())
                {
                    System.Data.OracleClient.OracleLob myLob = myReader.GetOracleLob(myReader.GetOrdinal("IMAGE"));
                    if (!myLob.IsNull)
                    {
                        string FN = myReader.GetString(myReader.GetOrdinal("IMAGE_NAME"));


                        //Use buffer to transfer data
                        byte[] b = new byte[myLob.Length];
                        //Read data from database
                        myLob.Read(b, 0, (int)myLob.Length);


                        Response.AddHeader("content-disposition", "attachment;filename=" + FN);
                        Response.ContentType = "application/octectstream";
                        Response.BinaryWrite(b);
                        Response.End();
                    }
                }
            }
            finally
            {
                myReader.Close();
                conn.Close();
            }
        }
 //total marks
 //procedure
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         String oradb = "Data Source=DESKTOP-K6AG53J;Persist Security Info=True;User ID=system;Password=student;";
         System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection(oradb);
         //conn.Open();
         System.Data.OracleClient.OracleCommand comm = new System.Data.OracleClient.OracleCommand();
         comm.Connection  = conn;
         comm.CommandText = "tot_marks";
         comm.CommandType = CommandType.StoredProcedure;
         comm.Parameters.Add("s_id", System.Data.OracleClient.OracleType.Number).Value     = s1;
         comm.Parameters.Add("co_id", System.Data.OracleClient.OracleType.Number).Value    = comboBox1.Text;
         comm.Parameters.Add("cout", System.Data.OracleClient.OracleType.Number).Direction = ParameterDirection.Output;
         conn.Open();
         comm.ExecuteNonQuery();
         textBox1.Text = (comm.Parameters["cout"].Value).ToString();
         conn.Close();
     }
     catch (IndexOutOfRangeException ex)
     {
         MessageBox.Show("Invalid Details!");
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// 执行连接
        /// </summary>
        /// <returns></returns>
        public string DoConn()
        {
            if (this.No == "local")
            {
                return("本地连接不需要测试是否连接成功.");
            }

            if (this.DBSrcType == Sys.DBSrcType.Localhost)
            {
                throw new Exception("@在该系统中只能有一个本地连接.");
            }

            string dsn = "";

            if (this.DBSrcType == Sys.DBSrcType.SQLServer)
            {
                try
                {
                    dsn = "Password="******";Persist Security Info=True;User ID=" + this.UserID + ";Initial Catalog=" + this.DBName + ";Data Source=" + this.IP + ";Timeout=999;MultipleActiveResultSets=true";
                    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();
                    conn.ConnectionString = dsn;
                    conn.Open();
                    conn.Close();

                    //删除应用.
                    try
                    {
                        BP.DA.DBAccess.RunSQL("Exec sp_droplinkedsrvlogin " + this.No + ",Null ");
                        BP.DA.DBAccess.RunSQL("Exec sp_dropserver " + this.No);
                    }
                    catch
                    {
                    }

                    //创建应用.
                    string sql = "";
                    sql += "sp_addlinkedserver @server='" + this.No + "', @srvproduct='', @provider='SQLOLEDB', @datasrc='" + this.IP + "'";
                    BP.DA.DBAccess.RunSQL(sql);

                    //执行登录.
                    sql  = "";
                    sql += " EXEC sp_addlinkedsrvlogin '" + this.No + "','false', NULL, '" + this.UserID + "', '" + this.Password + "'";
                    BP.DA.DBAccess.RunSQL(sql);

                    return("恭喜您,该(" + this.Name + ")连接配置成功。");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }

            if (this.DBSrcType == Sys.DBSrcType.Oracle)
            {
                try
                {
                    dsn = "user id=" + this.UserID + ";data source=" + this.DBName + ";password="******";Max Pool Size=200";
                    System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection();
                    conn.ConnectionString = dsn;
                    conn.Open();
                    conn.Close();
                    return("恭喜您,该(" + this.Name + ")连接配置成功。");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }

            if (this.DBSrcType == Sys.DBSrcType.MySQL)
            {
                try
                {
                    dsn = "Data Source=" + this.IP + ";Persist Security info=True;Initial Catalog=" + this.DBName + ";User ID=" + this.UserID + ";Password="******";";
                    MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
                    conn.ConnectionString = dsn;
                    conn.Open();
                    conn.Close();
                    return("恭喜您,该(" + this.Name + ")连接配置成功。");
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
            }

            //  if (this.DBSrcType == Sys.DBSrcType.Infomax)
            //{
            //    try
            //    {
            ////Host=10.0.2.36;Service=8001;Server=niosserver; Database=ccflow; UId=npmuser; Password=npmoptr2012;Database locale=en_US.819;Client Locale=en_US.CP1252
            //        dsn = "Data Source="+this.IP+";Persist Security info=True;Initial Catalog="+this.DBName+";User ID="+this.UserID+";Password="******";";
            //        MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection();
            //        conn.ConnectionString = dsn;
            //        conn.Open();
            //        conn.Close();
            //        return "恭喜您,该(" + this.Name + ")连接配置成功。";
            //    }
            //    catch (Exception ex)
            //    {
            //        return ex.Message;
            //    }
            //}
            return("没有涉及到的连接测试类型...");
        }
Exemplo n.º 10
0
 private void Form1_Closed(object sender, System.EventArgs e)
 {
     oracleConnection.Close();
 }
Exemplo n.º 11
0
 public void Close()
 {
     _con.Close();
 }
Exemplo n.º 12
0
 public void CloseDatabase()
 {
     connOracle.Close();
     connOracle.Dispose();
 }