Reputation: 21
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#.
Upvotes: 0
Views: 619
Reputation: 21
What ended up working for me was:
First just like @Pieterjan said-
Advantage.Data.Provider
(Version 8.10.1.2)Then-
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)dotnet run -r win-x86
Apparently the NuGet package can only be run with x86, I think that was the main problem
Upvotes: 1
Reputation: 3591
Install the Advantage Database Server dataprovider (ADS 8.1 provider)
Use the following code to create a database connection:
var connection = System.Data.Common.DbProviderFactories.GetFactory("Advantage.Data.Provider").CreateConnection();
connection.ConnectionString = "DATA SOURCE=C:\Ads\Databases\Example.add;ServerType=remote;USER ID=ADSSYS;PASSWORD=xxx;";
connection.Open();
var command = connection.CreateCommand();
command.CommandTask = "";
foreach (var param in Parameters) {
var par = command.CreateParameter();
par.ParameterName = "";
par.Value = "";
// par.DbType = System.Data.DbType.Boolean
command.Parameters.Add(par);
}
Modify your app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
...
<system.data>
<DbProviderFactories>
<clear />
<add name="Advantage Data Provider" invariant="Advantage.Data.Provider" description="" type="Advantage.Data.Provider.AdsFactory, Advantage.Data.Provider, Version=9.10.2.21, Culture=neutral, PublicKeyToken=e33137c86a38dc06" />
</DbProviderFactories>
</system.data>
</configuration>
Can you try that last part about the app.config
?
If you did all this, and it still doesn't work, then it'll be an ADS version mismatch. Versions of:
have to match.
Upvotes: 0