IBM DB2 Core:ASP.NET Core 2.1和Microsoft Enterprise Libraries的连接字符串

编程入门 行业动态 更新时间:2024-10-24 20:22:32
本文介绍了IBM DB2 Core:ASP.NET Core 2.1和Microsoft Enterprise Libraries的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用此 .Net Core的Microsoft.EnterpriseLibrary端口.它需要一个配置文件app.config,其中指定了连接字符串.我尝试使用在另一个工作项目中使用的相同连接字符串,但在这里不起作用.

I'm using this Microsoft.EnterpriseLibrary port for .Net Core. It requires a configuration file app.config with the connection string specified in it. I tried using the same connection string I use in another working project, but it doesn't work here.

如何为ASP.NET Core 2.1指定DB2连接字符串?

How can I specify a DB2 connection string for ASP.NET Core 2.1?

我这是我尝试过的:

<connectionStrings> <add name="Development" connectionString="server=MY.SERVER.COM:446;database=DBXX;user id=USERXX;password=PASSWORDXX;" providerName="IBM.Data.DB2.Core"/> </connectionStrings>

但是当我执行此操作时:

But when I execute this:

DatabaseFactory.SetDatabaseProviderFactory( new DatabaseProviderFactory( new SystemConfigurationSource(false).GetSection ), false ); var db = DatabaseFactory.CreateDatabase("Development");

它引发了这个异常:

Exception has occurred: CLR/System.InvalidOperationException An exception of type 'System.InvalidOperationException' occurred in Microsoft.Practices.EnterpriseLibrary.Data.dll but was not handled in user code: 'The connection string for the database 'Development' does not exist or does not have a valid provider.' Inner exceptions found, see $exception in variables window for more details. Innermost exception System.Configuration.ConfigurationErrorsException : The requested database Development does not have a valid ADO.NET provider name set in the connection string.

我认为提供商名称不正确,但是我在网络上找不到任何有效的示例.

I think the provider name is incorrect, but I can't find any working example on the web.

推荐答案

好,我解决了.原来我找不到IBM.Data.DB2.Core的任何提供程序,所以我这样配置了app.config文件:

Ok, I solved it. It turned out that I couldn't find any provider for IBM.Data.DB2.Core, so I configured my app.config file like this:

<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="system.data" type="System.Data.Common.DbProviderFactoriesConfigurationHandler, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null" requirePermission="true" /> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null" requirePermission="true" /> </configSections> <dataConfiguration defaultDatabase="Development" /> <connectionStrings> <add name="Development" connectionString="server=MY.SERVER.COM:446;database=DBXX;user id=USERXX;password=PASSWORDXX;" providerName="IBM.Data.DB2.Core"/> </connectionStrings> <system.data> <DbProviderFactories> <remove invariant="IBM.Data.DB2.Core" /> <add name="DB2 Data Provider" invariant="IBM.Data.DB2.Core" description=".Net Framework Data Provider for DB2" type="IBM.Data.DB2.Core.DB2Factory, IBM.Data.DB2.Core" /> </DbProviderFactories> </system.data> </configuration>

在研究IBM程序集时,我发现有一个名为DB2Factory的DbProviderFactory实现类.如果app.config文件配置了system.data部分,则可以使用该类代替提供者名称.

Exploring the IBM assembly, I discovered there was a DbProviderFactory implementation class called DB2Factory. That class can be used instead a provider name if the app.config file is configured with a system.data section as shown above.

更多推荐

IBM DB2 Core:ASP.NET Core 2.1和Microsoft Enterprise Libraries的连接字符串

本文发布于:2023-11-16 19:47:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607209.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   Core   ASP   IBM   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!