Welcome Guest, Not a member yet? Register   Sign In
connect to sql server with sqlsrv
#8

I do use multiple platforms with sqlsrv to connect to axapta database servers.
Maybe you need to use single quotes in .env file?

This is my code that does work, if this does not work for you, then most probably you have issue with connection IP address and / or DSN

.env
Code:
#--------------------------------------------------------------------
# DATABASE
#--------------------------------------------------------------------

database.default.hostname = localhost
database.default.database = intranet
database.default.username = intranet
database.default.password = intranet
database.default.DBDriver = MySQLi
database.default.DBDebug = true

# axapta server
database.axapta.hostname = 'xxx.xx.xx.xx'
database.axapta.database = 'database_name'
database.axapta.username = 'user_name'
database.axapta.password = 'long_password'
database.axapta.DBDriver = Sqlsrv
database.axapta.port = 1433

/app/Config/Database.php
PHP Code:
    /**
     * The Axapta database connection.
     *
     * @var array
     */
    public $axapta = [
        'DSN'      => '',
        'hostname' => '',
        'username' => '',
        'password' => '',
        'database' => '',
        'DBDriver' => 'Sqlsrv',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => (ENVIRONMENT !== 'production'),
        'cacheOn'  => false,
        'cacheDir' => '',
        'charset'  => 'utf8',
        'DBCollat' => 'utf8_general_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'     => 3306,
    ]; 

Controller
PHP Code:
$this->axapta Database::connect('axapta');

$builder $this->axapta->table('DATABASE_TABLE');
$builder->select();
$builder->where('TABLE_COLUMN''VALUE');
return 
$builder->get()->getResultObject(); 
Reply


Messages In This Thread
RE: connect to sql server with sqlsrv - by davis.lasis - 02-11-2021, 06:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB