Welcome Guest, Not a member yet? Register   Sign In
Unable to connect to SQLEXPPRESS
#1

Hello,
I'm a newbie here.
I use CodeIgniter for all my development in php since several years. I never posted on this forum but I read it often .
Today I create a account because I face a problem I don't understand. I don' know if it's my configuration or a bug. I thought it would be better to post that here before create a report issue on github.

I cannot connect to database starting from codeigniter v4.2.0. It works with codeigniter v4.1.9 on the same computer and with the same code.

The error mesage is : "Error connecting to the database: CodeIgniter\Database\Exceptions\DatabaseException: Fournisseur TCP : Aucune connexion n’a pu être établie car l’ordinateur cible l’a expressément refusée."
The database do not accept the connection.

I think the database configuration is ok because it works on v4.1.9.
I use php 7.4.5, apache and SQL Express 2019.

Below the database configuration in the ".env" file
Code:
database.default.hostname = localhost\SQLEXPRESS
database.default.database = Diag
database.default.username = Gmp
database.default.password = *******
database.default.DBDriver = sqlsrv
And here the model
PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
UtilisateursModel extends Model
{
    protected $table      'Utilisateurs';
    protected $primaryKey 'Id';
    protected $useAutoIncrement true;
    
    
protected $allowedFields = [
        'Nom',
        'Prenom',
        'Groupe',
        'NumBadge',
        'EstActif',
        'DateCreation',
        'DerniereConnexion',
        'EstConnecte',
        'Poste',
        'DerniereDeconnexion',
    ];


And there is nothing special in the controller
PHP Code:
<?php

namespace App\Controllers;

use 
App\Models\UtilisateursModel;

class 
Home extends BaseController
{
    public function index()
    {
        $model = New UtilisateursModel();
        var_dump($model->findAll());
    }

Do you have the same issue with SqlServer?
Thanks
Reply
#2

If the port is specified in the config, comment out the line. If not specified, please specify.

I do not remember where, but I saw the problem that it was not possible to connect with 4.2. Commenting out the line with the port helped.

For the sake of experiment, I installed SQL Express 14 (Windows) and without specifying the port, I could not connect to the database.
On tests (framework development), a connection with a port is used and they pass.

I don't know where this problem comes from.
Reply
#3

(08-11-2022, 12:01 PM)iRedds Wrote: If the port is specified in the config, comment out the line. If not specified, please specify.

I do not remember where, but I saw the problem that it was not possible to connect with 4.2. Commenting out the line with the port helped.

For the sake of experiment, I installed SQL Express 14 (Windows) and without specifying the port, I could not connect to the database.
On tests (framework development), a connection with a port is used and they pass.

I don't know where this problem comes from.

Effectively, when I comment the port in the config file it works.
I didn't find in SQL Server config where I can specify a port number. May be it is not the same.

Thanks a lot.
Reply
#4

TCP/IP configuration is set in the MS SQL server configuration manager:
C:\Windows\SysWOW64\SQLServerManager15.msc (for SQL Server 2019)
Standard port is 1433
Reply




Theme © iAndrew 2016 - Forum software by © MyBB