How to Resolve Database Access Error in SolidWorks API?

Dear colleagues, I am developing a program using the SolidWorks API, and the code snippet is roughly as follows:

IEdmFile5 aFile;
aFile = vault1.GetFileFromPath(filepath, out folder);
aFile.LockFile(folder.ID, this.Handle.ToInt32(), (int)EdmLockFlag.EdmLock_Simple);

However, when executing the last line, I consistently encounter the error: "Could not access the item in the database."
Could you please advise on how to resolve this issue? Are there any details I might have overlooked?