Releasing connection to a created Store

S

Steve Lang

Hi all,

I have the following (truncated) code. The problem is that after the code
has run, Outlook maintains a Write connection to the newly created backup
..pst file created at strBackupPath. I need it to be clear once the code has
finished in order to be able to do the process agin. Currently, all I can do
is close Outlook after this runs (it is part of a VB6 app) to remove the
connection.

Any ideas?
TIA and have a great day!
--
Stephen Lang
Legislative Counsel Bureau
Carson City, NV
GMT+8
slang at lcb <dot> state <dot> nv <dot> us

======CODE========

Set myOlApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
GoTo Done ' only fire if the application is already open
Else
Set myOlApp = Outlook.Application
End If

Set myNameSpace = myOlApp.GetNamespace("MAPI")

'determine the existing number of folders in outlook
NSCount = myNameSpace.Folders.Count

'add the backup location as a folder that we can use
myNameSpace.AddStore strBackupPath

Set newFolder = myNameSpace.Folders(NSCount + 1)
For i = 1 To NSCount 'dont want to include the backup folder itself
Set myFolder = myNameSpace.Folders(i)
'copy the subfolders in each to the backup dir
For y = 1 To myFolder.Folders.Count
myFolder.Folders(y).CopyTo newFolder
Next
Next
'remove backup store from outlook
myNameSpace.RemoveStore myNameSpace.Folders(NSCount + 1)

'deallocate variables
Set newFolder = Nothing
Set myFolder = Nothing
Set myNameSpace = Nothing
Set myOlApp = Nothing

=====END CODE======
 
K

Ken Slovak - [MVP - Outlook]

If you are lucky and wait for at least 5 - 10 minutes that store might
be unlocked. Usually the only way is to close Outlook to release it.

Why can't you reuse the store object again if you need it? Or create a
new one?
 
S

Steve Lang

Hi Ken,

Thanks for the quick response. I am using this process to automate backing
up user's e-mail (as part of a greater automated backup process). The way
the process works is at the beginning of the backup cycle, all the existing
data in the backup location is deleted. With Outlook holding the connection,
I can't delete the existing backup to create the new one. Even after 12
hours, I got an error indicative of a file lock. :^(

Is there any way to progammatically kill it? Or alternatively, another way
to backup my users' pst files?


Thanks again!

Steve
 
K

Ken Slovak - [MVP - Outlook]

You would have to exit Outlook and then restart it or you would have
to use different files each time. There's no other way around the file
lock Outlook puts on an open PST file.
 
S

Steve Lang

Hi Ken,

I think I may have found a way. Since the pst is on a network share, closing
the connection to the network share should break the file lock Outlook is
holding on the pst file. Then, all I would need to do is re-establish the
network connection, and Outlook's file lock will no longer exist. Sounds
good in theory, at least. If you are interested, I will let you know if it
works...

Steve
 
S

Steve Lang

It did work - after a fashion. I needed to break the lock, so I could delete
the pst when a new backup process was to start - even if Outlook had not
been rebooted. Disconnecting the network share allowed the pst to be
deleted, but I still had to do a different name (as you suggested) for each
successive backup, since Outlook - even if it couldn't get to the pst,
"remembered" it and wouldn't allow a new one with the same name.

To sum it up, using a unique name for the pst, and disconnecting the network
device to allow the old one to be deleted works great!

Thanks for your help!

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top