KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Sage 50/Actian Pervasive ODBC Connection #3402

Open Andrew Guattery opened this topic on on Dec 27, 2024 - 4 comments

Andrew Guattery commented on Dec 27, 2024

...Well the topic subject says it all - Is it possible to connect to Sage accounting (Pervasive/Actian DB) via ODBC? I can successfully Create an ODBC connection in MS Windows and then connect with it via php:

$dbh1 =  new PDO ("odbc:SAGE5064",$user,$pw);
$dbh2 = odbc_connect($dsn,$user,$pw); 
$result2 = odbc_exec($dbh2, $query);

However I cannot seem to create a connection in Koolreports:

    public function settings(){
        return array(
            "dataSources"=>array(
                "source1"=>array(
                    "connectionString"=>"sqlsrv:server=SQL ; Database=Mydb1",
                    "username"=>"xxxxxxx",
                    "password"=>"xxxxxx",
                    "charset"=>"utf8"
                ),
                "source2"=>array(
                "connectionString"=>"odbc:server=SAGE5064 ; Database=Mydb2",
                "username"=>"xxxxxxx",
                "password"=>"xxxxxxx"
                )
            )
        );
    }

"source1" works just fine with MSSQL - "source2" throws errors as it is not a defined source. Is there a generic method for ODBC or is there a way to define a custom connection?

Sebastian Morales commented on Jan 3

We have not had an ODBC datasource class yet. Given your code, does creating a PDO connection succeed?

$dbh1 =  new PDO ("odbc:SAGE5064",$user,$pw); // does this return false or a PDO object?

If this does return a PDO connection you can still use PDODataSource class.

Andrew Guattery commented on Jan 3

Sebastian, So we added this:

$user = "Xxxxxxxxx"; 
$pw = "xxxxxxxxx";

$dbh1 =  new PDO ("odbc:SAGE5064",$user,$pw);
$this->src('sage_values')->query($sql)->saveTo($fuel)->pipe($this->dataStore('fuel'));

This works, but obviously not using the datasource class. I was looking at writing a custom datasource so Koolreport could have it, but the documentation wasn't overly-clear and then I got sidetracked lol. Would be good if we could get an ODBC class...

Sebastian Morales commented on Jan 13

If you don't define the data source class, by default KoolReport uses PDODataSource which of course works with a PDO connection to your ODBC database. Is there any limitation that PDO has in comparison with a native ODBC connection?

Andrew Guattery commented on Jan 13

Sebastian, there really isn't a limitation; the bigger issue is some software vendors only support an ODBC connection to the data and do not allow for PDO. For example, you can connect to an Actian (Pervasive) database with PDO. And Sage 50 accounting uses a basic Pervasive database... BUT you cannot connect to Sage 50 with PDO out of the box (more on this in a second) - you need to create an ODBC interface. Sage has a built-in account connection manager for import/export and third party connections. While ODBC works (It is a PDO connection THROUGH ODBC) It just adds another layer of hoops to jump through. I guess my original post question is misleading; of course we CAN connect through ODBC, I guess what I meant to ask was "Does koolreport have a method for ODBC connections". So basically a class that is PDO that uses a passed-in ODBC connection. For some reason when we try to pass the connection to the PDODatasource class it doesn't work - manually adding it works. I did not get too far into debugging this but I'm 99% sure this is just an error in the connection string - being parsed wrong or something. If I get some time in the next day or two I will take a closer look at this and see if I can pinpoint the issue (could even be me doing something stupid....that never happens :-)

Finally FWIW: If I download the Actian Control Center I can open the Sage database and enable connections that are not allowed otherwise. This is obviously NOT the way to do it as this is not documented or supported.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None