1

I am using ZeroBrane IDE for lua script and Visual Studio 2015 for C# I can call lua script from C# with normal variable, but I can't run the script with sql-odbc, it's working in zeroBrane only but from c# I can't.

here is c# code

try
{
   Lua lua = new Lua();
   lua.DoFile("DGT_MSID.lua");

   var x = lua.DoString("return GetData()");
   Console.WriteLine(x.First().ToString());
} catch(NLua.Exceptions.LuaScriptException ex)
{
   Console.WriteLine(ex.Message);
}

DGT_MSID.lua script

function GetData()
  require "luasql.odbc"
  env = assert(luasql.odbc())
  print(env)
  con = assert(env:connect("conan", "sa", "p@ssw0rd"))
  print(con)
  cur = assert (con:execute"use testdb")
  cur = assert (con:execute"SELECT MSISD FROM MSID")
  row = cur:fetch({}, "a")

  while row do
    print(string.format("%s",row.MSISD))
    row = cur:fetch (row, "a")
  end

  cur:close()
  con:close()
  env:close()

  return row.MSISD
end

Here is this error:

error loading module 'luasql.odbc' from file '...\Debug\luasql\odbc.dll':The specified module could not be found

Puck
  • 2,080
  • 4
  • 19
  • 30
EngBashir
  • 21
  • 4
  • Have you copied the dll into the desired location? – dontpanic Jan 24 '19 at 09:34
  • all .dll files its already in luasql folder in debug directory. – EngBashir Jan 24 '19 at 12:26
  • An issue i had with using `nlua` was that the `require("luasql.odbc")` would only look outside of my `lua` folder so if i had `..\lua\lua_odbc.lua` and `..\lua\luasql\odbc.dll` it would only look for `..\luasql\odbc.dll` and fail to find it – Nifim Jan 24 '19 at 19:48
  • its working only with lua51, and NLua using lua52, how to solve this issue ?? – EngBashir Jan 25 '19 at 20:36

1 Answers1

0

I suspect one of the dependencies of odbc.dll is missing or not being loaded (which may be the Lua DLL or some other library it's linked against). You can use dependency walker to get the list of dependencies and even run your application in "profile" mode, which will show all loaded DLLs as well as any failing loads and their related errors.

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • The odbc.dll working only with lua51.dll, it's not working with lua53 or lua52, and NLua using only lua52.dll !!!??? – EngBashir Jan 25 '19 at 20:35
  • That's expected, as each dll is compiled only against specific Lua interpreter. You need to compile odbc.dll against lua52 to get it working with NLua. You may try [twoface](http://corsix.github.io/twoface/) to see if it works for your project ("twoface is a DLL which consumes the 5.2 ABI and presents a 5.1 style ABI, thereby allowing a 5.2 program to load most 5.1 C libraries without the need for any recompilation.") – Paul Kulchenko Jan 26 '19 at 00:24