DSNLESS Connection Error

Hello All,

I am using PHP5. I am trying to connect PHP5 with Access 2007 using DSN less connection. I am using the following code to connect the database.

$conn = new COM(“ADODB.Connection”) or die(“Cannot start ADO”);

// Microsoft Access connection string.
$conn->Open(“DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=E:\\xampp\\htdocs\\ams\\MyPayroll1.mdb”);

// SQL statement to build recordset.
$rs = $conn->Execute(“SELECT EmpCode FROM Emp_Mast”);
echo “<p>Below is a list of values in the MYDB.MDB database, MYABLE table, MYFIELD field.</p>”;

// Display all the values in the records set
while (!$rs->EOF) {
$fv = $rs->Fields(“empcode”);
echo "Code: “.$fv->value.”<br>
";
$rs->MoveNext();
}
$rs->Close();

When i am connecting the DB with the above code it’s connecting correctly and gives me the result. The DB is in my local system.

But when i used the same code to connect the Access DB which is another system it gives me the following error.

Fatal error: Uncaught exception ‘com_exception’ with message ‘<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> [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.’ in E:\xampp\htdocs\ams\ est_dsnless.php:7 Stack trace: #0 E:\xampp\htdocs\ams\ est_dsnless.php(7): com->Open(‘DRIVER={Microso…’) #1 {main} thrown in E:\xampp\htdocs\ams\ est_dsnless.php on line 7

$conn->Open(“DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=E:\\xampp\\htdocs\\ams\\MyPayroll1.mdb”);

for this code i have replaced with

$conn->Open(“DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\\192.168.1.101\\d$\\xampp\\htdocs\\ams\\ estemp.mdb”);

Please anyone help me to get out of this error.

Thanks in Advance

Does the user account which your webserver/pphp is running with have access to that share? I noticed it is an admin share too, which may complicate things.

Use [fphp]file_exists[/fphp] to see if the process can read the .mdb.

No, it has no username and password to access the another system.And the mdb file is there. For testing i have created that file and put in the specified location

Your script cannot access that file, you need to resolve this. I would suggest it’s a permission issue, start looking into that.

I have given permission to everyone. I have tried giving all the permissions like SYSTEM,ADMINISTRATOR,USERS which is in security tab. I have given this permission using rightclick on the file properties and gave permission. Is this is the correct way. Is we need to set any other permission anywhere?

You’re accessing the .mdb through an admin share (D$), this means the the process on the web server needs to have administrative privileges on the machine hosting the .mdb.

Can you not share the ams folder on 192.168.1.101 directly ?

Now i shared the ams folder. I am getting the below error.

Fatal error: Uncaught exception ‘com_exception’ with message ‘<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file ‘(unknown)’. It is already opened exclusively by another user, or you need permission to view its data.’ in D:\xampp\htdocs\ams\ est_dsnless.php:8 Stack trace: #0 D:\xampp\htdocs\ams\ est_dsnless.php(8): com->Open(‘DRIVER={Microso…’) #1 {main} thrown in D:\xampp\htdocs\ams\ est_dsnless.php on line 8