• 读取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"];
  • 相关阅读:
    Root resource classes
    web.xml文件的作用
    Mac OS X 快捷键(完整篇) 转载
    Eclipse快捷键大全(转载)
    mac os 下如何清除/切换svn eclipse插件的用户
    N-Queens II
    接口是永远不能被实例化的
    Chpater 10: Sorting
    Java 理论和实践: 了解泛型
    EMQ X + ClickHouse 实现物联网数据接入与分析
  • 原文地址:https://www.cnblogs.com/MiyaQian/p/4155266.html
Copyright © 2020-2023  润新知