cancel
Showing results for 
Search instead for 
Did you mean: 

Runtime Error while connecting HANA DB from VS Code

sumedhahire
Explorer
0 Kudos
1,567

Dear Folks,

I am trying to connect SAP HANA instance from VS Code using .net 7.0.

I have installed .net7 SDK and SP

I am getting below error while creating HanaConnection object.

Exception has occurred: CLR/System.TypeInitializationException
An exception of type 'System.TypeInitializationException' occurred in Sap.Data.Hana.Core.v2.1.dll but was not handled in user code: 'The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.IO.FileNotFoundException : Cannot find a matching libadonetHDB.dll with version 2.11.14 - check the location in the HDBDOTNETCORE or PATH / LD_LIBRARY_PATH / DYLD_LIBRARY_PATH environment variables
(Process) HDBDOTNETCORE=C:\Program Files\sap\hdbclient\dotnetcore
(Machine) HDBDOTNETCORE=C:\Program Files\sap\hdbclient\dotnetcore
Searched paths and results:
C:\Program Files\sap\hdbclient\dotnetcore\libadonetHDB.dll : 2.14.22 : False
C:\Program Files\sap\hdbclient\dotnetcore\libadonetHDB.dll : 2.14.22 : False
C:\Program Files\SAP\hdbclient\ado.net\libadonetHDB.dll : 2.14.22 : False
at Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls()
at Sap.Data.Hana.HanaUnmanagedDll..ctor()
at Sap.Data.Hana.HanaUnmanagedDll.get_Instance()
at Sap.Data.Hana.HanaConnection..cctor()

You may refer below code for reference.

using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using TestCode.Models;
using Sap.Data.Hana;
namespace TestCode.Controllers;
public class HomeController : Controlle{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger){
_logger = logger;
HanaConnection conn = new HanaConnection();
conn.ConnectionString = "connectionstring";
conn.Open();conn.Close();
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}

Accepted Solutions (0)

Answers (1)

Answers (1)

michael_eaton3
Active Contributor
0 Kudos

This is a simple HANA client version mismatch, but it's not your fault. It can be solved in different ways, see this for a detailed explanation - https://stackoverflow.com/questions/45233832/ado-net-provider-for-sap-hana-version-mismatch-issue

Michael

sumedhahire
Explorer
0 Kudos

Thank you Michael for your responce.