我将这个Microsoft.EnterpriseLibrary 端口用于 .Net Core。它需要一个配置文件app.config
,其中指定了连接字符串。我尝试使用我在另一个工作项目中使用的相同连接字符串,但它在这里不起作用。
如何为 ASP.NET Core 2.1 指定 DB2 连接字符串?
我这是我尝试过的:
<connectionStrings>
<add name="Development" connectionString="server=MY.SERVER.COM:446;database=DBXX;user id=USERXX;password=PASSWORDXX;" providerName="IBM.Data.DB2.Core"/>
</connectionStrings>
但是当我执行这个时:
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.
我认为提供者名称不正确,但我在网上找不到任何工作示例。