KoolReport's Forum

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

MSSQL 2008 R2 connection does not work! #60

Open bysystem opened this topic on on Aug 4, 2017 - 13 comments

bysystem commented on Aug 4, 2017

Dear support team,

I just have tried to connect to my MSSQL Server 2008 R2 in the same company network from my XAMMP environment on a Windows10 PC as followed (via SQLSRVDataSource):

Remark: I have a correct connection from the same environment to my MSSQL Server within an other blank PHP application. So the needed drivers should be available on this machine.

<?php require_once "koolreport/autoload.php"; use \koolreport\processes\Group; use \koolreport\processes\Sort; use \koolreport\processes\Limit;

class SalesByCustomer extends \koolreport\KoolReport {

public function settings()
{
    return array(
        "dataSources"=>array(
            "mysql"=>array(
                'host' => '10.100.65.21',
                'username' => 'sa',
                'password' => '*************',
                'dbname' => 'NIKON_AutoRep_test',
                'charset' => 'utf8',  
                'class' => "\koolreport\datasources\SQLSRVDataSource"  
            ),
        )
    );
}

public function setup()
{
    $this->src('sales')
    ->query("SELECT NikonOrt,Umsatz FROM Reporting.autorep_v WHERE NikonOrt = 'Ahlen' AND Umsatz > 0")
    ->pipe(new Group(array(
        "by"=>"NikonOrt",
        "sum"=>"Umsatz"
    )))
    ->pipe(new Sort(array(
        "Umsatz"=>"desc"
    )))
    ->pipe(new Limit(array(10)))
    ->pipe($this->dataStore('autorep_v'));
}

}

The error message is:

"Fatal error: Uncaught Exception: Datasource not found 'sales' in C:\xampp\htdocs\AutoRep_Nikon\koolreport\KoolReport.php:188 Stack trace: #0 C:\xampp\htdocs\AutoRep_Nikon\SalesByCustomer.php(27): koolreport\KoolReport->src('sales') #1 C:\xampp\htdocs\AutoRep_Nikon\koolreport\KoolReport.php(31): SalesByCustomer->setup() #2 C:\xampp\htdocs\AutoRep_Nikon\index.php(4): koolreport\KoolReport->__construct() #3 {main} thrown in C:\xampp\htdocs\AutoRep_Nikon\koolreport\KoolReport.php on line 188"

Any idea what could be the reason?

Kind regards, bysystem

KoolReport commented on Aug 4, 2017

Your data source in your settings is "mysql" but you use src("sales") which is not existed. Pleaze change "mysql" to "sales" or vice versa

bysystem commented on Aug 4, 2017

Thx a lot for quick feedback!

I just changed it to "sales" and I get now an other error message:

return array(

    "dataSources"=>array(
        "sales"=>array(

"Fatal error: Uncaught Error: Call to undefined function koolreport\datasources\sqlsrv_connect() in C:\xampp\htdocs\AutoRep_Nikon\koolreport\datasources\SQLSRVDataSource.php:36 Stack trace: #0 C:\xampp\htdocs\AutoRep_Nikon\koolreport\core\DataSource.php(20): koolreport\datasources\SQLSRVDataSource->onInit() #1 C:\xampp\htdocs\AutoRep_Nikon\koolreport\KoolReport.php(193): koolreport\core\DataSource->__construct(Array) #2 C:\xampp\htdocs\AutoRep_Nikon\SalesByCustomer.php(27): koolreport\KoolReport->src('sales') #3 C:\xampp\htdocs\AutoRep_Nikon\koolreport\KoolReport.php(31): SalesByCustomer->setup() #4 C:\xampp\htdocs\AutoRep_Nikon\index.php(4): koolreport\KoolReport->__construct() #5 {main} thrown in C:\xampp\htdocs\AutoRep_Nikon\koolreport\datasources\SQLSRVDataSource.php on line 36"

KoolReport commented on Aug 4, 2017

I guess you do not have extension driver for sqlserver. You may try the PDO datasource, it is the same as mysql server database connection settings but replace with connection for your sql server. The PDO Datasource can connect to sql server. If you do not know how to put the connection please search google "PDO and sql server"

KoolReport commented on Aug 4, 2017

Here are settings:

dataSources=>array(
    "sales"=>array(
        'connectionString' => 'mysql:host=localhost;mysql:port=xxxx;dbname=xxxxx',
        'username' => 'username',
        'password' => 'password',
        'charset' => 'utf8',
    ), 
)
KoolReport commented on Aug 5, 2017

Full steps to get SQL Server working:

  1. Dowload Drivers and DLL for PHP http://msdn.microsoft.com/en-us/library/cc296170.aspx
  2. Edit php.ini enable extension
  3. Edit settings() function for connection
function settings()
{
    return array(
        "dataSources"=>array(
              'sqlserver' => array(
                   'connectionString' => 'sqlsrv:Server=tcp:123.345.444.333;Database=myDB',
                   'username' => 'username',
                   'password' => 'password',
               ),            
        )
    )
} 
bysystem commented on Aug 9, 2017

Thx a lot!! I have followed your hints and the MSSQL connection works fine now!

Only one last question to this topic: I get 2 notice lines on my report on the top. How to disable them? I tried with disabling warnings via "error_reporting(E_ERROR)" but no success:

Notice: Use of undefined constant dataSources - assumed 'dataSources' in C:\xampp\htdocs\AutoRep_Nikon\SalesByCustomer.php on line 12

Notice: Use of undefined constant dataSources - assumed 'dataSources' in C:\xampp\htdocs\AutoRep_Nikon\SalesByCustomer.php on line 12

I would like to share my MSSQL connection config steps with all other koolreport users with MSSQL connection problems:

  1. I have downloaded drivers install file (SQLSRV40.EXE) for PHP 7 (current PHP vers. in XAMPP from phpinfo is: PHP Version 7.0.16).
  2. I installed SQLSRV40.EXE and entered the path to the PHP extensions directory "C:\xampp\php\ext"

  1. In php.ini the corresponding extensions above are activated: ;YBC --> Download MSSQL drivers for PHP extension=php_sqlsrv_7_ts_x86.dll extension=php_sqlsrv_7_nts_x86.dll extension=php_pdo_sqlsrv_7_ts_x86.dll extension=php_pdo_sqlsrv_7_nts_x86.dll extension=php_pdo_sqlsrv_7_ts_x64.dll extension=php_sqlsrv_7_nts_x64.dll extension=php_pdo_sqlsrv_7_nts_x64.dll extension=php_sqlsrv_7_ts_x64.dll extension=php_pdo.dll

  2. Restart apache

  3. Finaly edited the settings() function (I removed the password below)

class SalesByCustomer extends \koolreport\KoolReport {

public function settings()
{
    return array(
		dataSources=>array(
			"sales"=>array(
			'connectionString' => 'sqlsrv:Server=tcp:10.100.65.21;Database=NIKON_AutoRep_test',
			'username' => 'sa',
			'password' => '*****',
			), 
		)
    );
}

Kind regards

KoolReport commented on Aug 9, 2017

Awesome! Thank you for posting more details. It definitely benefits others.

bysystem commented on Aug 10, 2017

Only one last question to this topic: I get 2 notice lines on my report on the top. How to disable them? I tried with disabling warnings via "error_reporting(E_ERROR)" but no success:

Notice: Use of undefined constant dataSources - assumed 'dataSources' in C:\xampp\htdocs\AutoRep_Nikon\SalesByCustomer.php on line 12

Notice: Use of undefined constant dataSources - assumed 'dataSources' in C:\xampp\htdocs\AutoRep_Nikon\SalesByCustomer.php on line 12

KoolReport commented on Aug 10, 2017

Hi, you should use "dataSources", covering with double quotes.

bysystem commented on Aug 10, 2017

Oh yes, thx for the hint! It works and the notice above does not appear anymore!

But now I got an other notice related Pivot.php: Notice: Undefined index: prefix in C:\xampp\htdocs\AutoRep_Nikon\koolreport\packages\pivot\processes\Pivot.php on line 295

Any idea how to handle this?

KoolReport commented on Aug 10, 2017

I will send the notice to developer of Pivot package and get back to you. Meanwhile, if you want to suppress error you should use:

error_reporting(0);
bysystem commented on Aug 10, 2017

Thx a lot, "error_reporting(0);" helps!

KoolReport commented on Aug 10, 2017

You are welcome :) anything please let me know.

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
wiki
solved

None