When you run it from c: or other dir under your security context, it works (ie, logged in as your user).
When you run it under the security context of the application, it does not work.
My guess is that the the user under which the application run has no rights on the database.