oracle 最簡單連接

一、工程 生成 可能要改成x64

 /// <summary>
        /// 最簡單測試 不用
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public WebResponseContent GetTest1(string pkId)
        {
            string strEms_list_no = string.Empty;
            try
            {
                //從Oracle數據庫中讀取時間信息              
                string conn = string.Concat(
                    @"Data Source=",
                    @"    (DESCRIPTION=",
                    @"        (ADDRESS_LIST=",
                    @"            (ADDRESS=",
                    @"                (PROTOCOL=TCP)",
                    @"                (HOST=jdepy-cluster.mflex.com)",
                    @"                (PORT=1521)",
                    @"            )",
                    @"        )",
                    @"        (CONNECT_DATA=",
                    @"            (SERVICE_NAME=SZBOOK)",
                    @"        )",
                    @"    );",
                    @"Persist Security Info=True;",
                    @"User Id=mid_cms;",
                    @"Password=eport"
                    );

                //OracleConnection 被標註爲已過時
                OracleConnection oc = new OracleConnection(conn);

                try
                {
                    oc.Open();
                    //OracleCommand 被標註爲已過時
                    OracleCommand cmd = oc.CreateCommand();
                    cmd.CommandText = "select * from v_logistics_data where ems_list_no='" + pkId + "'";
                    OracleDataReader odr = cmd.ExecuteReader();

                    while (odr.Read())
                    {
                        strEms_list_no = odr.GetString(0);
                        //Console.WriteLine(odr.GetOracleDateTime(0).ToString());

                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    oc.Close();
                }

                return webResponse.OK(null, strEms_list_no);
            }
            catch (Exception ex)
            {
                return webResponse.Error(ex.ToString());
            }
        }
View Code

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章