Description
Interbase version
SQL> SHOW VERSION;
ISQL Version: WI-V14.4.0.804
InterBase/x64/Windows (access method), version "WI-V14.0.0.97"
InterBase/x64/Windows (remote server), version "WI-V14.0.0.97/tcp (OKW157-VT01)/P15"
InterBase/x64/Windows (remote interface), version "WI-V14.4.0.804/tcp (Skylight)/P15"
on disk structure version 18.0
.NET Core 6
ASP.NET Project
Entity Framework/Interbase related packages:
<PackageReference Include="InterBaseSql.Data.InterBaseClient" Version="7.13.6" />
<PackageReference Include="InterBaseSql.EntityFrameworkCore.InterBase" Version="7.13.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.11">
I have Interbase 2022 installed on my local machine including the ODBC driver.
My Windows machine's encoding is set to ShiftJIS (as it is the default Japanese encoding).
The remote Interbase instance does not have an encoding set, which to my understanding means that it should default to the host machine's encoding. The host machine of that remote instance is also set to ShiftJIS.
If I connect to the instance using isql
, I can properly retrieve Japanese encoded text.
Since I am having trouble using Entity Framework's ORM functions as described here, I've set up a different endpoint to execute SQL directly which looks like this,
[HttpGet("test")]
public async Task<string> Test()
{
var result = "";
using (var command = db.Database.GetDbConnection().CreateCommand())
{
command.CommandText = "SELECT KANK_NAME1_KANJI FROM KANK";
db.Database.OpenConnection();
using (var reader = await command.ExecuteReaderAsync())
{
if (reader.Read())
{
result = "";
result += reader.GetString(0);
}
}
}
return result;
}
If I set the connection string to @"User=USERNAME;Password=password;Database=c:\DATABASE.GDB;DataSource=999.999.999.999
and execute it, I get this result,
�q�j�a���������������
It seems like I'm having some kind of problem with the encoding. I thought that I should perhaps try to specify the encoding inside the connection string, however if I set the connection string to @"User=USERNAME;Password=password;Database=c:\DATABASE.GDB;DataSource=999.999.999.999;Charset=SJIS_0208
and execute it, I get this result
InterBaseSql.Data.InterBaseClient.IBException (0x80004005): arithmetic exception, numeric overflow, or string truncation
Cannot transliterate character between character sets
---> arithmetic exception, numeric overflow, or string truncation
Cannot transliterate character between character sets
at InterBaseSql.Data.InterBaseClient.IBCommand.Fetch()
at InterBaseSql.Data.InterBaseClient.IBDataReader.Read()
at PDFCreationMicroservice.Controllers.ContactsController.Test() in C:\Users\micha\source\repos\PDFCreationMicroservice\PDFCreationMicroservice\Controllers\ContactsController.cs:line 35
at lambda_method5(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
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 Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
HEADERS
=======
Accept: text/plain
Host: localhost:7248
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36
:method: GET
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,ja;q=0.8,ja-JP;q=0.7
Referer: https://localhost:7248/swagger/index.html
sec-ch-ua: "Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"
DNT: 1
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-site: same-origin
sec-fetch-mode: cors
sec-fetch-dest: empty
I tried setting breakpoints and debugging this, and it seems like this is coming from the reader.Read()
call. It seems like perhaps the reader is unable to handle ShiftJIS?