0
votes

I'm trying to connect microsoft access database that resides on a mapped network drive.

If I copy the .mdb file and put it locally I have no problem connecting and running queries but as soon as I try connect to the live version on the network I fail.

Here is what I have

//Works

try {
    $dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=C:/xampp/htdocs/inventory/ORSDATA.mdb;Uid=; Pwd=;");
    }
catch (PDOException $e)
    {

//Does Not work

try {
    $dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=cerfs1/f:/orsdata/ORSDATA.mdb;Uid=; Pwd=;");
    }
catch (PDOException $e)
    {

Where cerfs1 is the name of the server f: is the actual server drive letter /orsdata is the server folder and orsdata.mdb is the database.

I have tried numerous variations using shared drive letter Y:/orsdata.mdb and IP address (10.50.10.12) instead cerfs1. I get the following errors:

Dbq=//cerfs1/orsdata/ORSDATA.mdb -> SQLSTATE[HY000] SQLDriverConnect: -1811 [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.

Dbq=//cerfs1/f:/orsdata/ORSDATA.mdb ->SQLSTATE[HY024] SQLDriverConnect: -1023 [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

Dbq=cerfs1/f:/orsdata/ORSDATA.mdb ->SQLSTATE[HY000] SQLDriverConnect: -1044 [Microsoft][ODBC Microsoft Access Driver] Not a valid file name.

Dbq=10.50.10.12/f:/orsdata/ORSDATA.mdb -> SQLSTATE[HY000] SQLDriverConnect: -1044 [Microsoft][ODBC Microsoft Access Driver] Not a valid file name.

//Shared Drive is Y which is mapped to F:/orsdata

Dbq=Y:/ORSDATA.mdb -> SQLSTATE[HY024] SQLDriverConnect: -1023 [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

I read as much as I possible could about trying to connect to a mapped drive / database but nothing I have tried seems to work. The odd thing is I can go in through Excel on my local computer and pull the data from the network drive, but not through php / xampp. Any help is very much appreciated.

1
How about changing all forward slashes to back-slashes?ChrisW
Thanks for the idea ChrisW same issues thoughnodsdorf
It's been a while since I created ODBC connections in Windows - does the connection in Data Sources seem to work ok?ChrisW
Yes, I can use Excel to retrieve data through the mapped Y drive via the "From Microsoft Query" data source connection tab. Thanks for the follow up.nodsdorf
Did you tried with UNC path? and does the Apache/IIS (which ever your using) user has permissions the read/write on the folder of the .mdb file?Sebastien

1 Answers

1
votes

I have following for connecting to database file on local drive:

$dbName = $_SERVER["DOCUMENT_ROOT"] . "\Includes\fileName.mdb";

And those for connecting to database file on network drive:

$dbName = "\\\\server\folder\application\fileName.mdb";
$dbName = "P:\application\fileName.mdb";

Followed by:

new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd;");

All of them are working.