It looks like connection string is not proper, but you said same connection string works for console application.. We require more artifacts to know the actual root cuase can you please reach out to IBM support team? this will help in expediting the process...
Original Message:
Sent: Tue July 18, 2023 10:06 PM
From: baixiong zhao
Subject: What is wrong with connection to DB2 database from .net core razor page application?
Thank you so much for your response.
I installed package EntityFrameworkCore 7.09 and unstalled/installed IBM.Data.DB2.Core and got following error message which is more specific the issues
System.ArgumentException: Invalid argument
at IBM.Data.Db2.DB2ConnPool.ReplaceConnectionStringParms(DB2Connection connection, String szValue, DB2ConnSettings& pSettings, DB2ConnSettingsInternal& pSettingsInternal, Boolean bAttach, Boolean pushDownStrAppended)
at IBM.Data.Db2.DB2Connection.set_ConnectionString(String value)
at IBM.Data.Db2.DB2Connection..ctor(String connectionString)
at IBM.EntityFrameworkCore.Storage.Internal.Db2SqlConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
at IBM.EntityFrameworkCore.Storage.Db2RelationalCommand.CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.InitializeReader(Enumerator enumerator)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.<>c.<MoveNext>b__21_0(DbContext _, Enumerator enumerator)
at Microsoft.EntityFrameworkCore.Storage.NonRetryingExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)
at lambda_method101(Closure, QueryContext)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at WebApplication1.Pages.InsertModel.GetDataByStopFriskID(String stopFriskID) in C:\VS2022NetCore\SRMSample\WebApplication1\Pages\Insert.cshtml.cs:line 31
at WebApplication1.Pages.InsertModel.OnPost(String buttonAction, String StopFriskID) in C:\VS2022NetCore\SRMSample\WebApplication1\Pages\Insert.cshtml.cs:line 43
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.ActionResultHandlerMethod.Execute(Object receiver, Object[] arguments)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
------------------------------
baixiong zhao
Original Message:
Sent: Mon July 17, 2023 02:48 AM
From: Archana Soni
Subject: What is wrong with connection to DB2 database from .net core razor page application?
Hi Zhao,
Thanks for reaching out to us..
.NET 8 is not yet supported, so if you are referring .NET8 it may create issues.
We suggest to use .NET 7 version of assemblies for :
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.5.23280.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.5.23280.1" />
And uninstall IBM.Data.DB2.Core provider, then try running your app.
<PackageReference Include="IBM.Data.DB2.Core" Version="3.1.0.600" />
If still it does not work then please reach out to IBM Support team with proper non-confidential re-pro application.
Thanks,
Archana
------------------------------
Archana Soni
Original Message:
Sent: Wed July 12, 2023 09:02 AM
From: baixiong zhao
Subject: What is wrong with connection to DB2 database from .net core razor page application?
I am working a new .net core Razor Page application using Visual Studio 2022 with framework 7.0 which accesses to DB2 to get data so I installed following packages from NuGet
<ItemGroup>
<PackageReference Include="IBM.Data.DB2.Core" Version="3.1.0.600" />
<PackageReference Include="IBM.EntityFrameworkCore" Version="7.0.0.200" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0-preview.5.23280.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0-preview.5.23280.1" />
</ItemGroup>
I registered DBContext in program.cs with the connection sting defined in appsettings.json as "CDWContext": "UID=XXXX;PWD=XXXX;dcdw12p;DSN=PDOAA;DBALIAS=PDOAA;" which I used in console app and works fine.
builder.Services.AddDbContext<MyCDWContext>(options =>
{
options.UseDb2(builder.Configuration.GetConnectionString("CDWContext"), si =>
si.SetServerInfo(IBMDBServerType.AS400, IBMDBServerVersion.AS400_07_02));
});
And
public class MyCDWContext : DbContext
{
public MyCDWContext(DbContextOptions<MyCDWContext> options)
: base(options)
{ }
public DbSet<People> People { get; } = default!;
}
When calling public void OnGet()
{
this.People = (from p in _context.People where p.hireDate == "02/18/2018" select p).ToList();
}
I got following error:
· ArgumentNullException: Value cannot be null. (Parameter 'source')
o System.ArgumentNullException.Throw(string paramName)
o System.ArgumentNullException.ThrowIfNull(object argument, string paramName)
o System.Linq.Queryable.Where<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)
o SRMForm.Pages.ListStopFriskModel.OnGet() in ListStopFrisk.cshtml.cs
+
20. this.People = (from p in _context.People where p.hireDate == "02/18/2018" select p).ToList();
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory+VoidHandlerMethod.Execute(object receiver, object[] arguments)
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
o Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
o Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
o Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
o Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
o Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
o Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7040
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5187
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\VS2022NetCore\SRM\SRMForm
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.ArgumentNullException.Throw(String paramName)
at System.ArgumentNullException.ThrowIfNull(Object argument, String paramName)
at System.Linq.Queryable.Where[TSource](IQueryable`1 source, Expression`1 predicate)
at SRMForm.Pages.ListStopFriskModel.OnGet() in C:\VS2022NetCore\SRM\SRMForm\Pages\ListStopFrisk.cshtml.cs:line 20
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.VoidHandlerMethod.Execute(Object receiver, Object[] arguments)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Can someone give me ideal to solve the issue? Thanks in advance!
------------------------------
baixiong zhao
------------------------------