Set WarningsReturnAsErrors = 0 before connection #4762
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We have moved
sqlsrv_configure('WarningsReturnAsErrors', 0);
prior tosqlsrv_connect($this->hostname, $connection)
because if there is a warning or an information message establishing the connection, it will treat it as an error and Codeigniter will throw an exception. Driver's configuration should be set prior the connection.Example:
![before](https://user-images.githubusercontent.com/50045374/120366679-3de14a80-c310-11eb-9155-bb924816e3c0.png)
Before change, exception shows up (image1): "Unable to connect to the database. Main connection [SQLSRV]: Driver's SQLSetConnectAttr failed", but it is thrown by information message (IM006), as we can see when executing
sqlsrv_errors()
(image2).Image1:
Image2:
![information message](https://user-images.githubusercontent.com/50045374/120366671-3c178700-c310-11eb-8fad-a0c1320531b4.png)
After change: Connection is established without problems:
![after](https://user-images.githubusercontent.com/50045374/120366676-3d48b400-c310-11eb-9f19-b240e5e8c724.png)
Checklist: