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

 

posted @ 2024-05-23 09:08  丁焕轩  阅读(3)  评论(0编辑  收藏  举报