1

Is there any way to connect db using oledb connection with asp.net core project ?

I've one project which is based on .net framework in which i connected oledb connection and it was working well.

Now, I've upgraded same project with asp.net core 2.2 or > 2.0 and i'm facing error like below.

Error Could not load type System.Data.OleDb.OleDbConnection

Problem is .net core sdk have system.data.dll but this dll doesn't have system.data.oledb.OleDbConnection.

For that i've added one package called System.Data.OleDb -Version 4.6.0 in asp.net core and project was build successfully.

It gave run time error.

I created one another library which is based on .net framework and call same method of that library from asp.net core project.

Also, i tried to put same methods at asp.net core project but got same error.

here is the code

1) Created one db class and did some oledb connection code with beside constructor.

2) Now i created object like below.

public DB(string dbConnectionStr)
{
  this.dbConnection = new OleDbConnection(dbConnectionStr);
  this.dbConnectionSP = new OleDbConnection(dbConnectionStr);
  try
  {
    this.dbConnection.Open();
    this.dbConnectionSP.Open();
  }
  catch (Exception ex)
  {
    throw ex;
  }
  this.DBConnectionStr = dbConnectionStr;
}



            DB db = new DB("Provider=SQLOLEDB.1;Server=DESKTOP-AM9J3JL;Initial Catalog=testdb;Persist Security Info=False;User ID=sa;Password=12345;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

Connection should be granted when i declared db class.but in asp.net core project due to system.data dll i am continuously getting below error.

Error Could not load type System.Data.OleDb.OleDbConnection v4.0.2

I got one solution using sqlconnection it was working in asp.net core but i've tons of codes and everything based on oledb connection. I don't want to change all the thing due to this error.

If anybody have relevant solution than kindly help me.

Awaiting for someone response.

Smi10
  • 99
  • 1
  • 8
  • 1
    Have you installed the [Windows Compatibility package](https://www.nuget.org/packages/Microsoft.Windows.Compatibility)? According to [this comment](https://github.com/dotnet/corefx/issues/23542#issuecomment-488836822), it should be in there (net core 3 tho) - and also there's [System.Data.OleDb](https://www.nuget.org/packages/System.Data.OleDb).. – stuartd Nov 04 '19 at 13:40
  • Please check this post. https://stackoverflow.com/questions/55696920/error-could-not-load-type-system-data-oledb-oledbconnection-from-assembly-system – wut-excel Nov 04 '19 at 13:47

0 Answers0