在 C# 控制台项目中使用企业库 DAAB

发布于 2024-08-29 05:49:21 字数 2051 浏览 6 评论 0原文

如何准备配置设置(App.config,也许?)我需要在 C# 控制台项目中使用 Enterprise Library 数据访问应用程序块?

以下是我目前在控制台项目中尝试使用 App.config 的内容。当我调用DatabaseFactory.CreateDatabase()时,它会抛出一个异常,其中显示:

“配置系统初始化失败”

<configuration>
  <dataConfiguration>
    <xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.
            Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data,
            Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
      <enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Northwind"
              xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
        <databaseTypes>
          <databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase,
            Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral,
            PublicKeyToken=null" />
        </databaseTypes>
        <instances>
          <instance name="Northwind" type="Sql Server" connectionString="Northwind" />
        </instances>
        <connectionStrings>
          <connectionString name="Northwind">
            <parameters>
              <parameter name="Database" value="Northwind" isSensitive="false" />
              <parameter name="Integrated Security" value="True" isSensitive="false" />
              <parameter name="Server" value="local" isSensitive="false" />
              <parameter name="User ID" value="sa" isSensitive="false" />
              <parameter name="Password" value="sa1234" isSensitive="true" />
            </parameters>
          </connectionString>
        </connectionStrings>
      </enterpriseLibrary.databaseSettings>
    </xmlSerializerSection>
  </dataConfiguration>
</configuration>

How can I prepare the configuration settings (App.config, maybe?) I need to use Enterprise Library Data Access Application Block in a C# console project?

Following is what I currently trying with an App.config in the console project. When I call DatabaseFactory.CreateDatabase(), it throws an exception which says:

"Configuration system failed to initialize"

<configuration>
  <dataConfiguration>
    <xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.
            Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data,
            Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
      <enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Northwind"
              xmlns="http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/data">
        <databaseTypes>
          <databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase,
            Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral,
            PublicKeyToken=null" />
        </databaseTypes>
        <instances>
          <instance name="Northwind" type="Sql Server" connectionString="Northwind" />
        </instances>
        <connectionStrings>
          <connectionString name="Northwind">
            <parameters>
              <parameter name="Database" value="Northwind" isSensitive="false" />
              <parameter name="Integrated Security" value="True" isSensitive="false" />
              <parameter name="Server" value="local" isSensitive="false" />
              <parameter name="User ID" value="sa" isSensitive="false" />
              <parameter name="Password" value="sa1234" isSensitive="true" />
            </parameters>
          </connectionString>
        </connectionStrings>
      </enterpriseLibrary.databaseSettings>
    </xmlSerializerSection>
  </dataConfiguration>
</configuration>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬心 2024-09-05 05:49:21

使用集成到 Visual Studio 中的企业库配置工具一旦您安装了企业库 - 它将确保您的配置 XML 设置正确。

Use the Enterprise Library Configuration Tool which is integrated into Visual Studio once you install the Enterprise Library - it will ensure your configuration XML is setup correctly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文