Skip to Content
0
Nov 23, 2022 at 09:03 AM

Runtime Error while connecting HANA DB from VS Code

403 Views

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 });
}
}