Welcome Guest, Not a member yet? Register   Sign In
MSSQL working in v4.1.1, not working in v4.4.3
#1

It is likely I'm missing something I should have updated. However, currently, I can't sort out what the issue is.

I've updated the application via composer. Updated the composer updates per the 31 update documents between the two versions (remove some stuff, run some commands).  We have ENV files (which are being loaded), the server does connect to the database (a basic sqlserver connection in PHP file works fine) - prior versions of CI are currently working on the same server (as I said v4.1.1).  I've updated all of the config and view files in the app folders. we've updated the spark code.

The error message is:

Code:
Unable to connect to the database.
Main connection [sqlsrv]: [Microsoft][ODBC Driver 17 for SQL Server]TCP Provider: No connection could be made because the target machine actively refused it.
SQLSTATE: 08001, code: 10061
[Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired SQLSTATE: HYT00, code: 0
[Microsoft][ODBC Driver 17 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. SQLSTATE: 08001, code: 10061

Which is saying the connection is being refused, however, the public folder has a testdb file with:

Code:
<?php

// Database connection settings
$servername = "***************";
$database = ""***************";";
$username = ""***************";";
$password = ""***************";";

// Connection options
$connectionOptions = array(
    "Database" => $database,
    "Uid" => $username,
    "PWD" => $password
);

// Establishes the connection
$conn = sqlsrv_connect($servername, $connectionOptions);

if ($conn === false) {
    die(print_r(sqlsrv_errors(), true));
} else {
    echo "Connected successfully<br />";
}

// SQL to execute
$sql = "SELECT * FROM Firedrill";

// Prepare the query
$stmt = sqlsrv_query($conn, $sql);

if ($stmt === false) {
    die(print_r(sqlsrv_errors(), true));
}

// Loop through the rows
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
    echo "<pre>";
    print_r($row);
    echo "</pre>";
}

// Close the statement and the connection
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

?>

And that works. So I know it isn't a connection or database connectivity, permissions issue (yes the passwords and all match exactly with the ENV file).

We are using a filter (authentication) which does database work (again, working in v4.1.1) which is where the error is coming from.

Any thing, pointers or clues I can check to see what I missed in the upgrade process?
Reply
#2

In v4.4.3 the connection.php file in the \vendor\codeigniter4\framework\system\Database\SQLSRV folder has:
Code:
if (strpos($this->hostname, ',') === false && $this->port !== '') {
            $this->hostname .= ', ' . $this->port;
        }

whereas the v4.1.1 doesn't. So, if you have ports set in your database.php config file, it will throw the errors I'd found. Once I removed the ports (by replacing with '' and not 0) in the app/config/database.php file, it worked.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB