AspCore3.1使用FreeSql链接ORacle数据库

1.以往C#基础自带的

            string connString = "User ID=TEST;Password=TEST;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.90.20)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = sid)))";
            OracleConnection conn = new OracleConnection(connString);
            var sql = "SELECT EPC,BARCODE FROM RFIDCODEENGINE WHERE EPC='" + epc + "'";
            try
            {
                conn.Open();
                OracleCommand cmd = conn.CreateCommand();
                cmd.CommandText = sql;//写好想执行的Sql语句 
                OracleDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    var epc1 = dr["EPC"];
                    var upc2 = dr["BARCODE"];

                }
                dr.Close();
                //return myReader;
                //MessageBox.Show(conn.State.ToString());
            }
            catch (Exception ex)
            {
                //ShowErrorMessage(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }

 

2.使用FreeSql

链接字符串应该为

"User ID=TEST;Password=TEST;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.90.20)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = sid)))";

StartUp.cs

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
            string connStr = Configuration.GetConnectionString("DefaultConnection");
            this.FreeSql = new FreeSqlBuilder().UseConnectionString(DataType.Oracle,connStr)
                .UseAutoSyncStructure(true)
                .UseLazyLoading(true)
                .UseNoneCommandParameter(true)
                .Build();
        }

 

记得引用Nuget包 FreeSql.Provider.Oracle

 

posted @ 2021-03-08 11:33  蜗牛的礼物  阅读(785)  评论(0编辑  收藏  举报