Search code examples
c#.net-5workeradvantage-database-server

AccessViolationException in .NET Core 5 with Advantage Data Provider


I need to connect to Advantage Database for a Worker I'm working on.

I'm using the NuGet package Advantage.Data.Provider like so:

var conn = new AdsConnection("Data Source=\\Users\\[mypath];Initial Catalog=Test.add; User ID=adssys; Password=passw; ServerType=LOCAL");

if (conn.State == ConnectionState.Closed)
{
    conn.Open();
}
return conn;

After adding lots of .dll in System32 to fix other errors, I'm now stuck in this one:

Exception has occurred: CLR/System.AccessViolationException Ocorreu uma exceção sem tratamento do tipo "System.AccessViolationException" em Advantage.Data.Provider.dll: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

I can't get it to work. I've tried using others NuGets like AdoNetCore.AseClient and iAnywhere.Data.SQLAnywhere, but they also cause errors.

If anyone could help me with this error or has a better solution to my problem, I would appreciate it.

I'm using VS Code and C#.


Solution

  • What ended up working for me was:

    First just like @Pieterjan said-

    Then-

    • Get ace32.dll, adsloc32.dll, axcws32.dll and adslocal.cfg from C:\Program Files (x86)\Advantage 10.10\ARC and put it in an environment path location (like System32, but it would be recommended to create a new one just for this)
    • Run the project with dotnet run -r win-x86

    Apparently the NuGet package can only be run with x86, I think that was the main problem