zoukankan      html  css  js  c++  java
  • 写入配置文件以及验证网络是否连通

            /// <summary>
            /// 向App。config写入字符串
            /// </summary>
            /// <param name="AppKey"></param>
            /// <param name="AppValue"></param>
            public static void SetValue(string ConnenctionString, string strKey)
            {
                XmlDocument doc = new XmlDocument();
                //获得配置文件的全路径
                string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

                //string strFileName = System.Windows.Forms.Application.StartupPath + "\App.config";
                doc.Load(strFileName);
                //找出名称为“add”的所有元素
                XmlNodeList nodes = doc.GetElementsByTagName("add");
                for (int i = 0; i < nodes.Count; i++)
                {
                    //获得将当前元素的key属性
                    XmlAttribute att = nodes[i].Attributes["key"];
                    //根据元素的第一个属性来判断当前的元素是不是目标元素
                    if (att.Value == strKey)
                    {
                        //对目标元素中的第二个属性赋值
                        att = nodes[i].Attributes["value"];
                        att.Value = ConnenctionString;
                        break;
                    }
                }
                //保存上面的修改
                doc.Save(strFileName);
            }

           /// <summary>
            /// 读出配置文件,验证网络是否连通
            /// </summary>
            public bool TestMethods()
            {
                conSql = new SqlConnection(CPDJConfig.ConfigurationManager.AppSettings["CONNSQLSTRYW"]);
                try
                {
                    conSql.Open();
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
                finally
                {
                    conSql.Close();
                }
                return false;
            }

  • 相关阅读:
    Free HTML5 Bootrap Admin Template
    js框架简明
    ELKF(Elasticsearch+Logstash+ Kibana+ Filebeat) 部署
    docker-构建 oracle12c-r2(12.2.0.1) 的镜像
    线上故障排查——drools规则引擎使用不当导致oom
    抓住业务核心,避免过度抽象
    Disruptor的应用示例——大文件拆分
    Disruptor3.0的实现细节
    Disruptor——一种可替代有界队列完成并发线程间数据交换的高性能解决方案
    大文件拆分方案的java实践(附源码)
  • 原文地址:https://www.cnblogs.com/conghua/p/3157427.html
Copyright © 2011-2022 走看看