SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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>\n";
    $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\test_dsnless.php:7 Stack trace: #0 E:\xampp\htdocs\ams\test_dsnless.php(7): com->Open('DRIVER={Microso...') #1 {main} thrown in E:\xampp\htdocs\ams\test_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\\testemp.mdb");

    Please anyone help me to get out of this error.

    Thanks in Advance

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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 file_exists to see if the process can read the .mdb.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Your script cannot access that file, you need to resolve this. I would suggest it's a permission issue, start looking into that.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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 ?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Member
    Join Date
    May 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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\test_dsnless.php:8 Stack trace: #0 D:\xampp\htdocs\ams\test_dsnless.php(8): com->Open('DRIVER={Microso...') #1 {main} thrown in D:\xampp\htdocs\ams\test_dsnless.php on line 8


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •