![]() |
Trying to connect my CodeIgniter 4.5.1 project to a SQL Server (14.0) database. Running on Windows with XAMPP, PHP version 8.2.
I downloaded the appropriate DLLs from Microsoft, put them in my PHP extensions folder and enabled the extensions In my .env file I entered the database information: PHP Code: database.default.hostname = "MYSERVER\TEST" I get the following error: Code: Unable to connect to the database. The server is running and the credentials are correct (I triple-checked). If I connect to the DB the "hard" way (using the same credentials), it works just fine (just dropped code below into my controller): PHP Code: $serverName = "MYSERVER\TEST"; I am probably just doing something incredibly stupid, but I have been staring at this for hours and I am at my wit's end. Anyone have an idea? Thank you for reading.
Microsoft SQL Server via the SQLSRV driver (version 2012 and above only)
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(04-24-2024, 03:50 AM)InsiteFX Wrote: Microsoft SQL Server via the SQLSRV driver (version 2012 and above only) According to this overview version 14.0 is MS SQL Server 2017, so it's way above 2012.
Try to set an empty string '' to port in the DB Config.
(04-24-2024, 05:44 PM)kenjis Wrote: Try to set an empty string '' to port in the DB Config. Thank you for your reply. However, the suggestion does not seem to work. I added the following line in my .env file: PHP Code: database.default.port = '' and now get this error message: Code: Unable to connect to the database.
What if you change Database Config file, and remove the config in .env?
(04-25-2024, 12:54 AM)kenjis Wrote: What if you change Database Config file, and remove the config in .env? Thanks again. I commented out all database related lines in .env. Removed the default config in app\Config\Database.php and replaced it with this: PHP Code: /** I thought that maybe the 'schema' setting was missing, but I still get the same error. Changing 'port' to '' does not change the error message. In both cases I get: Code: Unable to connect to the database.
This works for me in CI 4.4.6 with MS SQL Server Express 2019:
Code: public array $sqlsrv = [ Maybe this helps you... I had to remove the port and add dbo as schema.
That's it.
Adding 'dbo' as 'schema' and not having 'port' is the winning combination. Thank you so much!
If empty string '' for port does not work, it is a bug.
Quote:Empty string '' for default port (or dynamic port with SQLSRV). It would be helpful if you could send a PR for the bug fix. |
Welcome Guest, Not a member yet? Register Sign In |