C#的EF框架怎么连接Oracle数据库

C#的EF框架怎么连接Oracle数据库,第1张

安装odp.net

ODP.NET你不需要安装Oracle,不需要配置oracle.key文件,不需要配置TnsNames.Ora文件 不需要配置环境变量;完全的傻瓜式的在没有安装oracle数据库或者

客户端等任何oracle的产品的机器去访问Oracle数据库!

自定义的类 不能使用using。需要释放或者关闭的可以用using 比如

using(SqlConnection conn=new SqlConnection()){}

你只能

DashengDbContext context = new DashengDbContext()

contenxt.方法()

假设是AppSettings节点

string connectionString=

System.Configuration.ConfigurationManager.AppSettings["RSDbContext"]

或者 直接读取xml文件 即节点add 下的属性name=RSDbContext的

模仿下面的读取xml代码

//using System.Xml

/// <summary>

        /// 通过键获取appSettings的值

        /// </summary>

        /// <param name="key"></param>

        /// <returns></returns>

        public static string GetValueByKey(string key) 

        {

            XmlDocument doc = new XmlDocument()

            doc.Load(AppDomain.CurrentDomain.BaseDirectory + "config.xml")

            XmlNode node = doc.DocumentElement.ChildNodes[1] 

            //找到appSettings节点 

            foreach (XmlNode childNode in node.ChildNodes)

            {

                if (childNode.Name == "add" && childNode.Attributes["name"] != null && childNode.Attributes["name"].InnerText == key)

                {

                    return childNode.Attributes["connectionString"].InnerText

                }

            }

            return ""

        }


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/6460097.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-03-22
下一篇2023-03-22

发表评论

登录后才能评论

评论列表(0条)

    保存