-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: sqlsrv default port cause connection refuse #7624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: sqlsrv default port cause connection refuse #7624
Conversation
~ ignore default port when constructr hostname for sqlsrv driver
All code must conform to our Style Guide, which is based on PSR-12. composer cs-fix more info here. |
What is the issue? We have tests with SQLSRV port 1433, and all tests pass. CodeIgniter4/tests/_support/Config/Registrar.php Lines 85 to 102 in 1e7204b
|
~ add missing space (style guide)
run tests on a windows server 2019 with default (ms sql server) installation with php 8.2 - all database test fail with the following exception:
So its not valid to add the default port for sqlsrv when executing on a windows platform. |
@puschie286 I got the error occurs only on Windows server. I don't use Windows. |
@puschie286 Stupid question... have you checked that the port number you are trying to use is correct? https://www.mssqltips.com/sqlservertip/2495/identify-sql-server-tcp-ip-port-being-used/ |
@michalsn we use the default configuration, that is dynamic port ( Ref "By default, a SQL Server named instance is configured to listen on dynamic ports." ). this is probably the reason why the fixed port in the database config doesnt work with the default installation. @kenjis to support dynamic ports, we could use 0 as dynamic port number ( because 0 is not valid as a port number, there shouldnt any conflicts with other database driver ) |
@puschie286 Ok, now I'm lost. If you're using dynamic ports, why are you expecting |
@michalsn you're right, for dynamic port we should remove the port config entry. guess thats the easiest solution my concern is backward compatibility, some older installation use static 1433 and new installation dynamic port - and both will work without a port definition. because the default config has the 'port' entry, you might think you need to define it and a quick search will give you the anwser that 1433 is the default port for ms sql server. maybe a notice in the database configuration documentation would be enough to help users to configure sqlsrv driver for new installations. for now we will apply a migration ( on our end ) that remove all sqlsrv port entries with the value of 1433 to have the backward compatibility with old installations |
@puschie286 Ok, now I understand what you mean. Thanks. I'm not a fan of the proposed change. I don't want us to end up with a situation where someone defines a port as A much more appropriate approach would be to add a note in the user guide - just like you mentioned. |
I'm lost. I'm not sure, but are you saying that latest SQL server on Windows is installed to use dynamic port by default? |
~ remove old port changes + add port config information to the documentation
@kenjis yes, dynamic port is the default setting nowadays. A named instance is an installation with an different instance name than the default instance name - overall its just an alias to identify the sql server instance ( if you have multiple on the same host ). if you dont provide the instance name, the driver use the default instance name - so its not possible to have an "unnamed instance" ( this term is sometimes used but it just refer to default instance name ). You could say that the instance name is microsoft way of omit the port i removed my change and added these information in the database configuration documentation |
@@ -174,7 +174,7 @@ Explanation of Values: | |||
**compress** Whether or not to use client compression (``MySQLi`` only). | |||
**strictOn** true/false (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL | |||
while developing an application (``MySQLi`` only). | |||
**port** The database port number. | |||
**port** The database port number - Empty for default port (or dynamic port with ``SQLSRV``) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean an empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - empty string is the only value that works for all driver
( sqlsrv and postgre doesnt use empty function for validation )
Co-authored-by: kenjis <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Description
database connection is refused when using sqlsrv driver with default port.
fixed by ignoring the default port ( 1433 )
Checklist:
Fixes: #6165
Related #6036