zoukankan      html  css  js  c++  java
  • 读取xml中数据库连接字符串

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    有关如何配置 ASP.NET 应用程序的详细信息,请访问
    http://go.microsoft.com/fwlink/?LinkId=301879
    -->
    <configuration>
    <appSettings></appSettings>
    <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    </system.web>
    
    <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
    </dependentAssembly>
    <dependentAssembly>
    <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
    </dependentAssembly>
    </assemblyBinding>
    </runtime>
    <system.webServer>
    <handlers>
    <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
    <remove name="OPTIONSVerbHandler" />
    <remove name="TRACEVerbHandler" />
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    </system.webServer>
    <connectionStrings>
    <add name="WaiterDeviceDbConnStr" connectionString="data source=192.168.19.79;initial catalog=POS20141202;persist security info=True;user id=datascan;password=DTSbsd7188228" providerName="System.Data.SqlClient" />
    </connectionStrings>
    </configuration>

    1) 以上是webservice项目中的 web.config文件,需要读到数据库连接信息

      可以直接用 string conStr = ConfigurationManager.ConnectionStrings["sqlString"].ConnectionString;

    2)如果是自己新建的xml文件,也可以直接从xml中读取信息

      XmlDocument xmlDoc = new XmlDocument();
      xmlDoc.Load("config.xml");
      XmlNode conNode= xmlDoc.SelectSingleNode("configuration/connectionStrings/add[@name='SqlString']");
      string conn = conNode.Attributes["connectionString"];
  • 相关阅读:
    请求重定向,请求转发
    post、get方法乱码问题
    Servlet
    修改Servlet模板,让Servlet更清新
    Java-Python对垒之质数计算
    使用Packet Tracer对不同网段组网模拟
    哑编码的两种方法
    AdaBoost scikit-learn相关参数
    KNN scikit-learn相关参数
    递归思想的应用-根据二叉树的中序遍历和前序遍历重建二叉树
  • 原文地址:https://www.cnblogs.com/MiyaQian/p/4155266.html
Copyright © 2011-2022 走看看