我正在使用此 .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的连接字符串
发布评论