Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Error 3050 Could Not Lock File

Recently, I have finished re-develop an in house VB6 application using access database.
The executiable program is in the users' local machine and the database in on NT server. Users have been getting error 3050 when they read or write to files and lost everthing they entered. All I can find from the MSDN is to change the MaxLocksPerFile value to 128 in its sample code. However, it did not help. Can anyone tell me what might cause it and its solution? Thanks so much.

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Error '3050' Couldn't Lock File
Hi all. This is my first post in this forum. I would like to say this is a great site and I have gotten a lot of helpful information from this site.

I have written a program that connects to an Access db located on a Novell network. I can run the program with no problems from my computer. I loaded it onto the computers that will need to run it and when the other computers load it the error message '3050' couldn't lock file was displayed when trying to open the database. I searched the forum but didn't find anything that made sense to me. Microsoft explains that it has something to do with writing to the .ldb file but their solution is still doesn't help me entirely. Basically I don't quite understand the .ldb file that is created when the db is opened and if that even has anything to do with the error. Any help would be greatly appreciated.


VB Error 3050 Couldn't Lock File????
I have 2 users (of hundreds) getting this error. I have a VB6 front to an access DB. Any ideas what it is?


Error 3050 Cannot Lock Database !!??
Dear VBForum

Can anyone explain why, only very occasionaly, I get ISAM related Error 3050 "cannot lock database" when running my application.

So far this has only happened on a Win2K sp2 computer. I've had a good browse around and as far as I can see this error only pops up when dealing with networked/shared databases. My application just uses an access database, password protected, to store its info locally in the app path. The database has been renamed not to have the .mdb extension for security reasons, and it has the extension .tdf (would this have anything to do with it?) Only the App would ever access this database at any one time so no sharing problems.

The error is difficult to re-create and only pops up very occasionally, but I really do want to try and eliminate this runtime problem as I have users in 5 countries running my app on all sorts of Windows versions

I am using this to manipulate the database


Dim dbs As Database
Dim rst As Recordset

'open database
Set dbs = OpenDatabase(App.path & "DatabaseName", False, False, _
"MS Access;pwd=password")

Set rst = dbs.OpenRecordset("TableName", dbOpenTable)

With rst


'close database

Set dbs = Nothing
Set rst = Nothing

End With


Can anyone help?

Thanks y'all

Error Number 3050

I go the following error message in my visual basic proiect: Error 3050 - Couldn't lock file. In my program I am using a database connection.
Does anyone know what could be the problem? After I gave a restarat to the computer it is functionating well. But it is strange this to me:).
Please write to me.
Many thanks,

Access Security Error # 3050
Hi there
I have an Access Application, which I have Access Security level Applied to it, and it works fine in my computer, But as I copy it form my computer to another computer, as soon as I try to open it I get the access MsgBox “could not Lock file” and in the help of that MsgBox, I get this Error # 3050
“The operating system will not allow Microsoft Jet to create a Lock file .LDB in the database file (.MDB) resides. You need to have write privileges to the directory…”

What do all these mean?
A note when I made my Access Security Levels, I created a new workgroupfile (use WRKGADM.EXE). And also the rest of procedures, as you know.

Best regards

Couldn't Lock File Error
Hi, I need a bit of help with this one.

I've developed a small vb-database application for an intranet environment. The database is MDB format, and the application uses a data control to access it, using DYNASET as the recordset type. This database is used for READING purposes only, no updates will be made to it. I've set the READONLY to TRUE, and the EXCLUSIVE to FALSE.

The database is located in an intranet folder, where most users have only READ access.

After installation, we noticed that many users are getting a "COULDN'T LOCK FILE" error, and the application shuts down. We also noticed that users with a read/write access to the folder a working fine.

How can this be? All of the settings indicate that this is a read-only database, so why is write access required?

Any help would be greatly appreciated.

ADODB File Sharing Lock Error
I have an established ADO 2.7 connection to an existing Access 2000 database and I am successfully able to manipulate the existing data.

However once the number of manipulated records reaches approximately 9400 records, I receive the following runtime error:

"-2147217887 (80040e21), file sharing lock count exceeded. Increase MaxLocksPerFile registry entry".

I am not sure what to do to correct this error.

If I used batch updates, I thought this would have corrected the problem, but it did not appear to.

The number of records within the database will fluctuate between 500 and 300,000 records.

If needed I can attach the code and the database (if it helps).

File Sharing Lock Count Exceeded Error
This occurs when I try to delete an item, and access cascades the deletes through many tables with over 1 million records.  I am aware of the registry setting that allows you to bump up the number of records you can lock but this will not be an option b/c:

1.  It looks like the max won't be enough to complete this delete.
2.  I don't want to have to change everyone's registry settings.

I know I can go through and delete each individual record, but isn't there a way that you can tell access "Hey, I have the database opened exclusively so don't worry about locking every single affected record!!!"???  Thanks for any help you can give... even if it is just saying "Nope, I don't know of a way."  Thanks!

Vb 6.0 Error When Hit Run: Unable To Initialize Appliation Lock File Terminating The

when I hit Run this error message is thrown..

can some one let me know what could be reason.

Error Increase Lock Count Per File In Registry Entry
i am using vb as front end and access as backend
Osystemcon is a connection object
i have not provided any locking system

When I execute query
Osystemcon.execute " alter table outwards_header alter column vatamt
double default 0"

for some databases where data is huge it give a error file sharing lock
error increase lock count per file in registry entry

for other databases where data is not so huge it will not give error it will
work fine .how can i solve the problem

i want to change data type of vatamt from single to double. will do events
solve the problem please explain me about do events and file sharing lock
error. Thanks in advance

File Lock Or Folder Lock
Is there any api i can use to lock files or folder, preventing them to be accessible from the user???

i tried to open the file without any sharing, it works alright, but it would be a little slow if i want to lock a folder with many many files in it...

"Can't Lock File" Error For Database Using Visual Basic
Ok, I have searched this board for a while now trying to find the answer, and it seems that no one has really answered the problem at hand. I am running a vb6.0 app on serveral windows 2000 boxes that all must connect to an access database. i have tested the program here on my local machine (as a single user on the database) and the program runs fine, not a bug in site.

I installed the same program on another machine here on the network, and it worked fine as well. We both opened the program at the same time, modified the database at the same time, and everything, and still everything works fine. these tests were run on windows xp boxes.

The solution I need is this. I am delivering this software to another company where like i said, they are using 2000 boxes. when one user tries to open the program, they get the can't lock file error. they now have full control of the database (the it guys over there were big on security and had the security controls down to basically read-only). yet still, it doesn't work. the catch is this, the it guys who have administrative privileges, as well as the supervisor, run the program with no gliches.

Does anyone have an answer to any of this. Is it because of the Windows xp deal? is it because of the visual basic way of dealing with the database (I am dao for this one, i could change to ado if necessary), or is it because the users don't have admin privileges (as a side note, i do not have admin privileges on the network here at work, and in fact the database was stored in a very secured folder on the network when it was running here)

any help would be great


Help...vb6.0 Error: "unable To Initialize Application Lock File"
I get this error when I run the project file in vb6.0 environment.
any reasons why this could be happening?

Detect Num Lock Caps Lock And Scroll Lock <solved>
i am creating a small password username program and the password is case sensitive and i want it to be but i want to warn the user if the caps lock or num lock or scroll lock is on, though i do not know to detect if these are on , anyone know thanks!.

Best Reguards

Dave Barr

Edited by - crazyoldman on 1/11/2006 11:38:51 AM

"Couldn't Lock File" Error On VB
I have an Access97 database on the LAN. All computers have NT4 sp 6. The LAN permissions are setup to "Everyone Full Control".

There's a VB program which is always executing onto 4 computers. Each of these computer regularly send requests to the Access97 database. It's SQL requests (by Database object .Execute function) and requests made by Recordset object functions (.Update, .AddNew, .Edit, etc.)
Requests of all type are made (creating, reading and deleting records). All these requests are quick but are send often (1 for each 10 seconds).

My problem is that if 2 of the 4 computers send a request in the same time, i've got the following error message on the computer that send his request the second:
"Couldn't lock file" (error number is 3050).

I know that this error occur when the database .ldb file exist
(it mean that a request is executing for an another computer).

But Access97 is supposed to be shared. So it is supposed to accept multiples requests in same time from differents computers! And the 4 computers don't use the same tables in the database (each computer have his tables). So, I don't understand why I got the message!!!!

Can you tell me the reason of the error and how I can
erase the problem.


Excuse me if there are errors in the text, I speak french...

"couldn't Lock File" Error
Hi everyone,

I was curious if anybody else receives this error. I'm currently using the DAO Data control to access an .MDB database. My program works fine, but occasionally the database is not accessible to anyone and users receive a "COULDN'T LOCK FILE" error.

I've noticed that every time this happens, the associated .LDB file is locked and cannot be deleted or moved. When the .LDB file is finally accessible (sometimes 1 or 2 days later), the database is fine.

Is this a common problem?


"Couldn't Lock File" Error
I have developed an Access DB with VB GUI (with DAO access method), it needs to be a stand alone application running fully from the CD and hence no component is residing on the clients computer. I have two major problems:

1. I need to silently install jet drivers if they don't exist on the clients computer and I have no idea how to go about this and there are no refernce points on the net either!

2. When running the application from the CD I get a "Couldn't lock file" error. I tried including the lock file (ldb) but that didn't help either!

Any help is greatly appreciated.

ps. As it stands I intend to: during the first run I install jet drivers and leave an .INI file and after that I check against the INI file in my form load. If you have any other suggestions let me know!

Many thanks, all of your help is appreciated


Error "Could Not Lock File"
Hi All,

any idea how to solve if i've got "Could not lock file" error? i'm using VB6 + Access 2003.. i've got this error at OpenDatabase code.. thanks!!

Num Lock, Scroll Lock && Caps Lock QUestion
How can i activate the Num Lock, Scroll Lock & Caps Lock using vb?

Run-time 3050 Occurs When Opening An Exe That Is Run Off A Database Stored On A Cd
Hello all

I have a bit of a problem here. What I am doing is creating a VB application that is to be run off a cd (autorun). I have a menu and 2 of the menus are photo galleries. Now my photo galleries get their information from Microsoft access databases. When I run this program on my computer it is fine, but if I run it on anyone elses computer I get that run-time error 3050 error, Could not lock file.
Now I think this means it cannot write the ldb file which makes sense because it cannot write onto a CD. However I run the program on my machine and it does not create a .ldb file. Does anyone know why this is happening.

Edited by - jjoseph on 6/14/2005 4:21:01 PM

Pessimistic Lock Error
Hi there!

We are working on a project, written in VB5SP3 using Access95(7.0) mdb-s via the VB-s Jet engine.
The project works in more than 100 pharmacy. It has a central computer with the global .mdb-s (~500MB)
and has 1-8 other workstations with the Software running on.
I use a number generating routine which based on a table in one of the global .mdb-s.
One record in this table stores a number and the program reads it and increments it's value.
I open the recordset in Pessimistic mode so all the workstation must get back different numbers.
But it's not True, different workstations sometimes gets the SAME number.
How can it be?

Here is the important part of the routine:

Public Function GetLieferscheinNummer() As Long
On Error GoTo EH
Set recParameter = dbCIDANova.OpenRecordset("Parameter") 'It opens the recordset in Pessimistic mode!
lngParameterNummer = recParameter!PRM_LetzteLieferNr
recParameter!PRM_LetzteLieferNr = lngParameterNummer + 1
Exit Function
If LockErrorHandler(vntTime) Then 'This function handles if it's a lock error and waits a little
ShowErrorMessage Err.Number, Error$, "GetLieferscheinNummer", Screen.ActiveForm.Caption
End If
Resume EF
End Function

Suvak Lajos

Repeating Lock Error Unhandled
So -- I have a multi-user database application which uses an Access 2000 database. As a result, it has occasional errors when one user tries to access it at the same time as the next -- the lock error.

To fix that, I basically added error code that would retry a few number of times, since after a retry or two the original user was out of the database:

Public Function RegCheck() As Integer
On Error GoTo ErrControl
dim intErrCount as integer
'now get registration code from database

'Prepare to Populate Messages
Dim adoRec As New ADODB.Recordset
adoRec.Open "SELECT Code FROM Practice", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBloc, _
adOpenStatic, adLockOptimistic

'various manipulation code here

'now exit sub and have error procedure after
Exit Function

'clean up first try
Set adoRec = Nothing
'first, just try it again 5 times
If intErrCount < 5 Then
intErrCount = intErrCount + 1
GoTo Start
End If

'if it makes it through 5 tries, then record the error.
ErrorRecord "RegCheck -- Module 2", Err.Number, Err.Description
End Function

This fixed my problem for a while just fine, but now -- if the database is locked at the first use, it goes to 'ErrControl' just like it should, and retries. But the SECOND time it is locked, it does *not* call the Error handler. It just puts up the run-time error screen and crashes out.

Anyone have any idea why it does not use the error handler the second time?

This happens both running at full speed, or going line by line: The first error uses the error handler, the second doesn't. This is without leaving the procedure at all.

Unfinished MySql Transaction Lock Error
Hi there my fellow developers !

I'm having an annoying problem with MySql transactions being interrupted by an error and thus, being unable to be commited or rolledback.

I've made the programming in VBScript (ASP). It's a file parser in its first stage. During the parsing, it reads hundreds of lines and perform hundreds of select - insert - update's in the database.

Because each parsing process is a big unit, the transaction model is the best way to approach it. The thing is that when the FILE TO BE PARSED is formatted as it's supposed to be formated, everything goes fine, the transaction goes from begining to commit without interruptions.

But if the file has unexpected content, it produces an error that stops the script from rolling back the transaction. If you are familiar with ASP you may know that ASP doesn't have error handlers like ON ERROR GOTO SubN. The only thing I can use is On error resume next but this let the script continue (it shouldn't, it could make the script fall into an endless loop)

Anyway, it seems that the transaction remains "open" and everytime a user tries to repeat the parsing process with a different file, the database hangs for a while until it timeout with the server error 500-100 message: "Lock wait timeout exceeded; try restarting transaction"

INDEED! The previous transaction wasn't commited nor rolled back.
Is there a way, through ASP script to make all the "pending" transactions to be rolledback so the user can move on?

I can paste some codeif you need, but it would help if you are familiar with ASP and have had a similiar problem with transactions in MySql.

If you are wondering why the script produces error... because it's in an early stage and it reads thousands of elements per file. If some of those elements aren't of the correct data type the script produces error. Comparing each element read to verify it's of the correct type is a task I can't afford for a long time. So what I'm saying is that if the user doesn't provide the right file, it's correct for him to receive an error message, but the system shouldn't LOCK as it's doing.

Thanks a lot for your time, patience and insights !
Have a nice day.


Error Message "the Database Engine Could Not Lock...
when clicking on the button the code runs fine the first time, adding a user to a database, though when executed again i recieve the error:

"The database engine could not lock <table> because it is already in use by another person or process."

when i close the form and reopen it, i am able to click the button once with success but on the second click i still recieve the error noted above

here is my code:

Public Sub Enter_User_Click()
On Error GoTo Error_Handling

'turning the warnings off
DoCmd.SetWarnings False

'setting the focus

'getting nt userid entered into the textbox
stringUser = username1.Text

'checking stringUser
If stringUser = "" Then
'error message
MsgBox "NT user identification not valid, please enter a valid username.", vbOKOnly, "Osare"
'emptying the boxes
Exit Sub
End If

'opening Osare_Databases and creating a column with user's NT id
DoCmd.RunSQL "ALTER TABLE Osare_Databases ADD COLUMN " & stringUser & " varchar(20);"

'opening Osare_User and entering id information
DoCmd.RunSQL "INSERT INTO Osare_User ([Userid]) VALUES (stringUser);"

'opening Osare_User and updating admin information
DoCmd.RunSQL "UPDATE Osare_User SET Admin = 'no' WHERE Userid = stringUser ;"

'refreshing the combobox

'emptying the boxes

'adding information to the log file
stringLogInfo = "user: " & stringCurrentUser & " added a user to the Osare user list"
Log_Info (stringLogInfo)

End Sub

important info:
Log_Info and Empty_Boxes are other methods
the variables i use here are declared globally

any clues on how to fix this error??? perhaps i should close the table at the end of each event... help!!


Lock File
I had lock file while my app run, and suddenly the power come out.
Can I access my file again? Help me

My code : Open .. lock read..


File Lock
hi all,

how do u lock a .txt file?

Lock A File
How do I lock a file that I am going to write on?.
I will be using a shared file, and I don't want the integrity problems that could arise when writing on it whilst other application is doing the same.
Is there any function or way of doing it?

File Lock?
how can i check to see if a file if locked, often times when I attempt to delete a certain file the file is locked by another application and I cannot delete it from vb, so my question is how can i check to see if a certain file is locked? I am using SHFileOperation so i could just let windows do the error but nah

thanks for your time and i look forward to your replies.

Could Not Lock File

I'm using Microsoft Access as the database. I have few locations of user will connect to this database. When run the program, certain time the user will hit the error saying that could not lock file? Any one have any idea what caused the problem?

Appreciate for the help.


Lock File

I am makeing a small program that will enable the user to select an exe program and it makes it password protected, basily all it does is combine the exe to protect into the main exe, witch is then run and prompts for a password, if the password is correct the exe to run is extracted and then executed.

now what I whould like to know is how can I lock this file, meaning when the app is extracted as explained above and run, I need a way for the user 1 not to rename , copy or move the file.

any ideas?


Lock A Doc File
I am using the following code to export crystal report 9 into a word Document.

VB Code:
Dim appl As New CRAXDRT.ApplicationDim rep As CRAXDRT.Report Set rep = appl.OpenReport("C:Book2
eport4.rpt", 1)rep.RecordSelectionFormula = "{Btest.BID} =" & narrep.ExportOptions.DiskFileName = ssfilenamerep.ExportOptions.DestinationType = crEDTDiskFilerep.ExportOptions.FormatType = 14rep.Export False

What I want is to not allow the user to be able to edit the report.
How can I do it?

Lock A File Or Reg Value
is there a way to lock a file or a string in the registry?(with out keeping the file open)

what i mean by lock is make it so the user cannot delete it.

i know you can make it hidden but i dont care if the user views it i only care if the user deletes it.

i have a login thing that i dont want the "Admin" to be deleted, i dont care about all the other users just the "Admin"


Cannot Lock File!! Please Help
My Access database is connected to Vb6 and at first it was working perfectly but after using the package and deployment wizard, the application cannot locate the file! The actual error message that is displayed is "cannot lock file.

The database is connected through the floppy drive because i need to use the application on other pc's because the database would be found easily!

Is it because I need to provide a dynamic reference to locate the database instead of a:/ ? How do u do that? Please help!

How To Lock A File
"lockfile" and "lockfileex"
i want to lock a file that i m working on and i belive that these are the api functions that i need to use but i dont know how to use them.
i need your help !
thank you

Using A Lock File
Im semi new to VB

Here is the story.
I have an instant messenger program (network) that if more than one instance is running on separate computers, then the user will not get his messages.

What I tried to do to fix this was create a lock file (h:!lock.lck) at load time and dump some text into it. H: is the users personal network drive. If the filesize was greater than zero after opening another session it kicked em out with a msgbox stating they have more than one instance running. at close or errortraps it closes then kills the file.

this works great. one problem, lets say you power off the PC without closing and deleting the lock file. that files still exists next time you try to open a session and then the user has to delete the lock file manually. This is no good.

I have tried to work with the fact that if another instance is running then the file would be read only because it is in use. I have run into noting but dead ends. its quite a maze.

Thanks for any help

Lock Txt File
Hey everyone

Is it possible to get VB to lock a txt file so that it cannot be edited by another prog (e.g. Notepad), even over a network?

Thanks for any help received.


- Chris
If it ain't broke - don't fix it

File Lock
how can i check to see if a file if locked, often times when I attempt to delete a certain file the file is locked by another application and I cannot delete it from vb, so my question is how can i check to see if a certain file is locked?

thanks for your time and i look forward to your replies.

Lock File Or Folder
This is my first post to this excellent forum and I'd like to start by asking a question, if I may.

I know a function called "LockFile" exists in the Windows API, but I do not know how to use it to lock a specific file or folder from access. Could anyone please tell me how to do so?

Any help would be greatly appreciated.

Couldn't Lock File

Greetings from Mexico City.

I have a VB 6 application running on a Jet (Access 97) database. The database is on my NT 4 server and my stations range from Windows 98 to Windows XP. The application has been running perfectly for the last 4 years. I'm trying to migrate the database to a Windows 2000 server. I have an administrator's account with all the possible rights, but whenever I try to run the application I get the error 3050. Any ideas?

Thanks a million

Ldb Database Lock File .............
Did anyone here facing the same problem? Have any solution or any step to prevent the lock file again?

File Lock Software
Can anyone send me free software for file lock(text files) with passsword protection. I got many softwares from net, but some don't seem to work ad others are trial versions. I want a good filelock software without trial verison. Pls help me...

Test For File Lock?
If I have locked a file in VB, how can I test for that lock from a different VB program?

For example, ProgA:
Open file Lock Read Write
write some stuff...

While ProgA has the file open,
ProgB should test for the Lock
before attmepting to open it for Read/Write.

How Can I Delete Lock File?? Help Me Pls!
Hi all,
I use Access for storing and managing dabatase for multi_user but i don't know why i can use one more person.
Whenever i open Access file , another one can acess that file. I saw a lock file and i cannot delete it. Is there any way for using multiuser with one Access file??
Lock file type:Access.LockFile.9
Help me pls.
Thanks so much

Lock Text File?

Is it possible to lock a text file so that the user cannot open it while it's locked by my application? And I don't just mean not be able to delete.. What I means is that while my application is running, I don't want the text file to be able to be read..

Any help or example would be appreciated..


File Lock Problem

I am attempting to check if a text file is allready open by another application before i rewrite it or delete it..
I have created a file and opened it in say Wordpad.

Have tried the 2 methods below..neither of them seem to pick up an error.

On Error GoTo FileIsOpen:
    hdlFile = FreeFile
    Open strFullPathFileName For Random Lock Read Write As hdlFile

Fsys.DeleteFile (strFullPathFileName)

Is there any reliable way of checking if a file is open by another non vb program......

Appreciate any help


How To Lock File Types
I have a Quiz program written in VB6 that reads/writes to an Access database. The program can create new databases and edit/delete current ones too. The problem is that anyone can open the databases and look at questions and answers. Is there a way to render the database files unreadable to a user through another application like Notepad or Access? Basically what I want is for the database files the Quiz program is using to be unreadable/unwriteable to any program except the Quiz program that is accessing them.

Any help you are able to give is greatly appreciated. If I am not clear, just post a reply, I am at work fot 6 more hours and will be keeping a vigilant watch.


How To Lock A Text File...
Hi, can someone show me how to lock a text file say "VB.TXT" for editing.. i want to open the file and manipulate strings written, and while doing this, i want the file to be "lock" for editing.. and will unlock it after editing.. thanks!

Lock File Connection Ado
i have multiuser aplication in net (3 PC A,B,C) with the same program who connect (SQL) to C:DATA.DBF file on PC "A". How to lock connection from another users PC B,C (when user A have opened connection to dbf file) and give them msgbox "dbf connetion is busy please try again later" ????

please help me

Lock Word File From VB

I am trying to open word from VB. I have already opened the word document inside the VB form. Now I want to lock this document , which means the user should not be able to copy or paste anything from this document. He should be shown the message box whenever he clicks on the document inside my application.

Can anybody help me. If yes that would be a great ....


Copyright © 2005-08, All rights reserved