Adding parameters to connection string

Get help from other users here.

Moderators: Developer, Contributor

Post Reply
Phroobar
Posts: 40
Joined: 13 Dec 2022, 16:14

Adding parameters to connection string

Post by Phroobar »

How can I additional parameters to the database connection string?
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: Adding parameters to connection string

Post by cas »

Can you please elaborate on this? What do you want to add for which reason? What is the OS, DB en Mantis version?
Phroobar
Posts: 40
Joined: 13 Dec 2022, 16:14

Re: Adding parameters to connection string

Post by Phroobar »

The web site is on IIS 8 on windows 2016 servers. Since the database is on an always on SQL server 2017 server, we need to add MultiSubnetFailover=yes to the connection string. Otherwise the server will time out. We are using ODBC driver 18 with latest adodb drivers and mantis 2.25.5.
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: Adding parameters to connection string

Post by cas »

Guess you need to check that with the suppier of the ODBC software :mrgreen:
Phroobar
Posts: 40
Joined: 13 Dec 2022, 16:14

Re: Adding parameters to connection string

Post by Phroobar »

Since Mantis doesn't allow you to pass an entire connection string from the config since p_dns$ is false, I modified the core\database_api.php to include

$g_db = ADONewConnection($t_db_type)
line 154 added $g_db->SetConnectionParameter('MultiSubnetFailover','Yes')

This seems like very poor design choices by the developers. We should be able to add more parameters than database, username and password. There has to be a better way to do this.

Also the point of having the database password in clear text in a config file is completely unsecure since stack trace errors show this string to anyone.
atrol
Site Admin
Posts: 8531
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: Adding parameters to connection string

Post by atrol »

Phroobar wrote: 05 Oct 2023, 17:24since p_dns$ is false
It's not false if you set $g_dsn in your config_inc.php

Code: Select all

/**
 * adodb Data Source Name
 * This is an EXPERIMENTAL field.
 * If the above database settings, do not provide enough flexibility, it is
 * possible to specify a dsn for the database connection. For further details,
 * currently, you need to see the adodb manual at
 * http://phplens.com/adodb/code.initialization.html#dsnsupport. For example,
 * if db_type is odbc_mssql. The following is an example dsn:
 * "Driver={SQL Server Native Client 10.0};SERVER=.\sqlexpress;DATABASE=bugtracker;UID=mantis;PWD=password;"
 * NOTE: the installer does not yet fully support the use of dsn's
 */
$g_dsn = '';
Phroobar wrote: 05 Oct 2023, 17:24since stack trace errors show this string to anyone.
Not to anyone, just to users that have access to PHP error logs on the server and you configured MantisBT in a non-recommended way (set $g_show_detailed_errors = ON;)
Please use Search before posting and read the Manual
shadymorais
Posts: 3
Joined: 21 Mar 2023, 15:18

Re: Adding parameters to connection string

Post by shadymorais »

Hello and sorry for reviving this old thread.

I looked around and i couldn't find any answer and after several hours of trying a bunch of things I'm lost. Like Phroobar i'm trying to add Multisubnetfailover and i can't figure out why i can't.
I'm not the original admin of this MantisBT instance but i was placed in charge with little handover so any help will be much much appreciated.

My environment is mantis 2.25.1, windows server, php 7.4 and SQL server 2019 in a cluster
When i add $g_dsn = ' '; to config_inc.php the likes loads normally but after adding, in my case

Code: Select all

$g_dsn = 'driver={ODBC Driver 17 for SQL Server};Server=Myserver;Database=myDatabase;UID=myUser;PWD=myPwd;';
I get a adodb error:
Missing file: drivers/adodb-driver={odbc driver 17 for sql server};Server=Myserver;Database=myDatabase;UID=myUser;PWD=myPwd;.inc.php

ADONewConnection: Unable to load database driver ''

From my understanding it seems it's not able to load the proper driver for it, i have checked and the php extensions "php_pdo_sqlsrv.dll" and "php_sqlsrv.dll" are present in the folder and in the php.ini and the adodb drivers are the ones provided with the Mantis Install if i'm not mistaken. I went into the drivers folder for adodb and the files seem to be there.
Maybe it's just not passing the parameters correctly.

I tried adding the $g_db->SetConnectionParameter('MultiSubnetFailover','Yes') after the ADONewConnection but in the test environment (where i don't have a cluster) did nothing and in the Prod i made the page not load after i restarted the services so i quickly reverted.

Any help or direction will help me a bunch.
Kind regards.
Post Reply