Search code examples
luafreetdsapache2.4dbdmod-lua

apache 2.4 - Cant get Sybase database connection using mod_lua, mod_dbd, freetds


We are migrating our python scripts to lua scripts as part of apache 2.4 upgrade. One of the requirement is connecting to Sybase database and execute queries. To do that we have developed a small code using mod_lua api to get db connection, but we haven't been successful.

We have installed the apr-util with freetds.

To get the database connection using mod_lua, mod_dbd and freetds - we followed the steps mentioned here - http://modlua.org/api/database#dbd

To configure the DPDParams for freetds, we followed the params mentioned here https://httpd.apache.org/docs/2.4/mod/mod_dbd.html#DBDParams

In VirtualHost of httpd.conf, we have added the following dbdparams

DBDriver freetds

DBDParams username=xxx,password=xxx,host=host-ip:port

DBDMax 10

and the lua code, just for getting a database connection is

require "apache2"
require "string"
function handle(r)
r.content_type = "text/html"
local database, err = r:dbacquire("mod_dbd")
r:err("inside handle method_1  " .. err)
return apache2.OK
end

The error we are getting in apache error log is-

[Thu Aug 25 15:28:03.198044 2016] [dbd:error] [pid 21708:tid 139621318366976] (20014)Internal error (specific information not available): AH00629: Can't connect to freetds:

[Thu Aug 25 15:28:03.198145 2016] [dbd:error] [pid 21708:tid 139621318366976] (20014)Internal error (specific information not available): AH00633: failed to initialise

[Thu Aug 25 15:28:03.198184 2016] [lua:error] [pid 21708:tid 139621318366976] [client 10.135.15.148:52836] inside handle method_1 Could not acquire connection from mod_dbd. If your database is running, this may indicate a permission problem.

​We are able to connect to the database using tsql from the same system, but connection from apache dbd, is not working. We are suspecting that there might be some configuration(DBDParams) problems or that the OS may be blocking connection from apache

Could someone please help in this regard.


Solution

  • We found the solution. The problem was there in the DBDParams we were passing. For connecting to sybase, we were providing the connection details(host:port) in the 'host' param(host=). On futher looking into the apr-util-freetds code, we found that for Sybase connection it is the **server(server=) param where we should provide the host port connection details**.

    http://www.freetds.org/reference/a00371.html#gaef0e7a5fcf2d8c8f795b2b06ce4de8b1

    The DBD Params which worked for Sybase connection using freetds is - DBDParams username=xxx,password=xxxxxx,server=h.o.s.t:port

    Its a bit confusing because in sybase terms host is normally the server hostname/ip.