Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to unlock the database Which is being accessed ?

Posted on 1998-07-16
5
Medium Priority
?
138 Views
Last Modified: 2010-05-03
My question is how can i unlock the database (data.mdb) which is being accesses by the my vb program.
The reason i want to do that is because i want to replace the current updated  database
with the original one (which is the backup .mdb) when the user press close button.

netcool
0
Comment
Question by:netcool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 1466057
You need to close the database and set the object to nothing I think

db.close
set db = nothing


0
 
LVL 5

Author Comment

by:netcool
ID: 1466058
deighton,

i tried but not working. Let me explain what i encouter and what ineed to be done.
I open the database and many recordset during my program running, so now i want to unlock/close  the database in order to delete the database and replace it with new one
(same name) .I can't delete the mdb file because it atatched with .ldb file unless i exist my program.
Another question, do i have to always set db = opendatabase("c:\data.mdb") whenever
i need to open recordset set tb = db.openrecordset("Employee") ????

Netcool

0
 
LVL 18

Expert Comment

by:deighton
ID: 1466059
The database needs to be open for you to open a recordset.  But you can open a database and then open and close as many recordsets as you like on that database, before finally closing the database.

You must always make sure that your databases and recordsets have been closed after use.  Avoid the following

function misuse() as integer

dim db as database
dim rs as recordset

set db = workspaces(0).opendatabase("x.mdb")
set rs = db.openrecordset("x",dbopendynaset)





end function

You always have to have rs.close then db.close at the bottom of the function

e.g

function ok() as integer

dim db as database
dim rs as recordset

set db = workspaces(0).opendatabase("x.mdb")
set rs = db.openrecordset("x",dbopendynaset)



rs.close
db.close



end function


You can  make the db a global or form level variable then do the following sort of thing

in declarations

dim db as database

the in form load or form initialse you open the database e.g. set db = workspaces..  etc

You then open and close recordsets in your form whenever you need them.  Finally you must do db.close in the form unload or  terminate event.

I think you might be leaving databases or recordsets open by accident.  See if this helps

0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1466060
Right.  And because of bugs in the MS code in various versions of VB and .dlls, it's always adviseable to set your objects = Nothing after closing them, in order to clean out all references to them in the OS.  Then you should be able to operate on your .mdbs as just another file, assuming nobody else in another app is using them.
0
 
LVL 18

Accepted Solution

by:
deighton earned 120 total points
ID: 1466061
You need to close the database and set the object to nothing I think

      db.close
      set db = nothing


      then open and close as many recordsets as you like on that database, before finally closing the
      database.

      You must always make sure that your databases and recordsets have been closed after
      use.  Avoid the following

      function misuse() as integer

      dim db as database
      dim rs as recordset

      set db = workspaces(0).opendatabase("x.mdb")
      set rs = db.openrecordset("x",dbopendynaset)





      end function

      You always have to have rs.close then db.close at the bottom of the function

      e.g

      function ok() as integer

      dim db as database
      dim rs as recordset

      set db = workspaces(0).opendatabase("x.mdb")
      set rs = db.openrecordset("x",dbopendynaset)



      rs.close
      db.close



      end function


      You can  make the db a global or form level variable then do the following sort of thing

      in declarations

      dim db as database

      the in form load or form initialse you open the database e.g. set db = workspaces..  etc

      You then open and close recordsets in your form whenever you need them.  Finally you must do
      db.close in the form unload or  terminate event.

      I think you might be leaving databases or recordsets open by accident.  See if this helps
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question