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;
            }

  • 相关阅读:
    Tensorflow的对二次函数的神经网络训练
    ubuntu16.04的Anaconda下的tensorflow安装py3.5
    数字信号处理C语言(3) ------FFT
    数字信号处理C语言(2) ------带高斯噪声的sin函数和组合sin函数
    数字信号处理C语言(1) ------均匀分布和高斯分布随机数
    CCIE学习笔记 ----TSHOOT
    CCIE学习笔记 ----BGP
    CCIE学习笔记 ----GRE over IPsec
    调试
    Java protobuf框架使用向导
  • 原文地址:https://www.cnblogs.com/conghua/p/3157427.html
Copyright © 2011-2022 走看看