Click here to Skip to main content
15,882,055 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi I had developed a program in Visual Studio 2005 (VB) and it worked fine in XP. The same program is showing error when installed on Windows 7. I have changed Advanced Compile Options to x86, Can some one throw light on this?

I get the following error:
System.Data.OleDb.OleDbException: Could not find file 'C:\Windows\system32\evqed.mdb'.

In my program the database file "evqed.mdb" is placed in application folder with following code:
ctrdirPath = System.IO.Directory.GetCurrentDirectory
ctrdirPath = ctrdirPath & "\evqed.mdb"

This works fine in my development PC and gets installed and runs as well,. Only in other PCs I get this error.

(The program uses Speech DLL and Microsoft Accesss 2003)

Thanks in advance
V L Patil
Updated 17-Oct-12 3:48am
[no name] 14-Oct-12 10:11am    
"System.IO.Directory.GetCurrentDirectory" does not always mean the directory that your program is running in.

First, it was a stupid idea to put a datbase file in System32. That folder is Read Only for normal users, so they can't use that database at all.

The same is true for any folder path under Program Files.

The solution comes in two parts. The first is to find a more appropriate place to put your database files, or any other file the user is going to need to modify. You can look at the documentation on the Environment.GetFolderPath() method and the enum it uses, Environment.SpecialFolder.

The second part is where you read up on Windows 7 security.
Share this answer
PatilVL 15-Oct-12 1:25am    
Thanks for your reply. when I developed this code and deployed in XP OS the following code executed properly
ctrdirPath = System.IO.Directory.GetCurrentDirectory
ctrdirPath = ctrdirPath & "\evqed.mdb"
I placed all database files and other files through Deployment Project. But when this is run on Windows 7 I get the path to be C:\Windows\system32\!
Dave Kreskowiak 15-Oct-12 7:42am    
NEVER use GetCurrentDirectory unless you're writing an app that has to manipulations from a command prompt window.

Use the well-known paths you find in the SpecialFolder path enumeration and GetFolderPath, as I've already said.

I don't care if it worked on XP. You were using a bad practice to begin with.
PatilVL 15-Oct-12 8:30am    
I had placed all database files and other resources in Application Folder in
Deployment / SET UP Project and expected to access these files from the application folder where exe will be available. Only way to access these files was from getdirectory method.Do you think that this is wrong practice?

Are you suggesting that these resource files must NOT be placed in application folder in Deployment Project? I will be thankful for your reply...
Dave Kreskowiak 15-Oct-12 10:10am    
That's NOT the only way to access those files. Using CurrentDirectory is bad because the CurrentDirectory can change during the course of your application if you're not very careful.

Using well-known path roots, like ProgramFiles is far better because those paths never change.

You cannot put files that will be opened read/write (like your database) in any path under Windows or Program Files because those paths, and their subfolders, are ReadOnly to users!

A normal place to put those kinds of files in under CommonAppData or something similarly appropriate, based on your application requirements.

Again, I direct you to GetFolderPath and the SpecialFolder enumeration. READ IT!
PatilVL 15-Oct-12 10:37am    
Thanks a lot for your help
I suppose, you need the executing assambly's folder. Look around here:[^]. In many cases location property is enough:[^].
Be aware, that there are huge differences between XP and Win7 regarding default file access security, even with administrator (UAC[^]).
Share this answer
PatilVL 14-Oct-12 4:36am    
Thanks for your reply. Unfortunately I get error in file name as the path string returns a value
I think that because of "file:\" in the string I am not getting access to file.
Any idea?
Zoltán Zörgő 14-Oct-12 8:11am    
Well, just strip the "file" from the beginning. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900