Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#App.Config文件_C#_Sql - Fatal编程技术网

C#App.Config文件

C#App.Config文件,c#,sql,C#,Sql,请容忍我,我对c#还很陌生。现在我正在查看主项目中的app.config文件。代码如下: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.Data

请容忍我,我对c#还很陌生。现在我正在查看主项目中的app.config文件。代码如下:

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=vsfe2wed2/>
  </configSections>
  <dataConfiguration defaultDatabase="Testing"/>
  <connectionStrings>
    <add name="Testing" connectionString="Data Source=Test123;Initial Catalog=TestData;Integrated Security=True;" providerName="System.Data.SqlClient"/>
  </connectionStrings>


这不是代码。它只是一个包含设置的配置文件,除非您有一些代码使用它们,否则它不会做任何事情。它没有建立到数据库的任何连接,只是将连接字符串外部化,以便在编写数据访问层时不必在应用程序中对其进行硬编码。

这只是一个存根/示例配置文件,但除非您的代码实际与它指定的数据库通信,否则不会使用任何内容。它被设置为使用连接字符串“datasource=Test123;initialcatalog=TestData;integratedsecurity=True;”与数据库“Testing”对话

您可以在此处找到更多信息:

app.config(或web项目的web.config)仅包含配置信息。它不直接做任何工作,它只是所有配置值的中心位置

您可以使用类从配置文件中检索设置,以便在您自己的项目中使用

ConfigurationManager.AppSettings["SettingsKey"];