码迷,mamicode.com
首页 > Web开发 > 详细

NET CORE 3.1 Orac Daper

时间:2020-07-03 12:31:38      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:catch   throw   oracle   try   using   stat   ase   def   action   



Install-Package Dapper -Version 1.50.5
Install-Package Oracle.ManagedDataAccess.Core -Version 2.12.0-beta2

appsettings.json
  "ConnectionStrings": {
    "EmployeeConnection": "data source=xxx;password=xxx;user id=xxx;Incr Pool Size=5;Decr Pool Size=2;"
  }



   public class HomeController : Controller
    {
        IConfiguration configuration;
        public HomeController( IConfiguration _configuration)
        {
            configuration = _configuration;

        }
        public IActionResult Index()
        {
            return Ok(GetAppRoot());
        }
        public string GetConnection()
        {
            var connectionString = configuration.GetSection("ConnectionStrings").GetSection("EmployeeConnection").Value;
            return connectionString;
        }
        public string GetAppRoot()
        {
            string querySql = @" select id
                                     from  user where  id=1";

            return GetSingleString(GetConnection(), querySql);
        }
        public string GetSingleString(string conn, string querySql)
        {
            using (var Conn = CreateConnection(conn))
            {
                return Conn.Query<string>(querySql).FirstOrDefault();

            }
        }
        public static IDbConnection CreateConnection(string connString)
        {
            IDbConnection conn = null;
            try
            {
                conn = new Oracle.ManagedDataAccess.Client.OracleConnection(connString);
                conn.Open();
            }
            catch (Exception ex)
            {
                throw new Exception("Database can not open.", ex);
            }
            return conn;
        }
    }

 

NET CORE 3.1 Orac Daper

标签:catch   throw   oracle   try   using   stat   ase   def   action   

原文地址:https://www.cnblogs.com/LiuFengH/p/13229576.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!