Did you know… You will receive “Cannot open the PST because it is in use.” error when you configure SQLMail to use an internet mail server by using Outlook 2003

It is not recommended that you use Outlook 2002 or Outlook 2003 together with SQL Mail and with Internet mail servers that use SMTP or POP3. More info on this is available at http://support.microsoft.com/?id=897349 .

Below is a practical workaround if you really need this to work.
Plan here is to make sure SQL Agent starts up only when Outlook is started successfully at the time of System start up.


1.       Make sure the SQL Agent Start up is set to Manual. Make sure you remove the Outlook from the start up folder

2.       Open Outlook. Go to Tools > Macro > Visual Basic Editor. This should open the Visual basic Editor. (The shortcut key to open the editor is Alt + F11)

3.       On the left pane under Project1, Right click "Microsoft Office Outlook Objects" and select Insert -> Module. This will create a new Module1 under Modules

4.       Now Select the Run Sub/User form option from the Run menu or alternatively press the F5 Key to execute project. This should Pop up the Macro window.

5.       Give a The Macro name as MacroAgent and click on the Create Button. This will create the function Sub Macro Agent()

6.       Copy the Below Code Between the Sub MacroAgent() and End Sub

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='SQLSERVERAGENT'")
For each objService in colServiceList
errReturn = objService.StartService()

Set colServiceList = objWMIService.ExecQuery("Associators of " _
& "{Win32_Service.Name='SQLSERVERAGENT'} Where " _
& "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
errReturn = objService.StartService()

7.       Click on the Save Icon and Close the Visual Basic Editor

8.       On Outlook Go to Tools ->Macro ->Security. Select the Low Security Level Option. Click Ok to apply the settings

9.       Open Registry (regedit). Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

10.    Create a new String Value as OutlookAgent. Double click the OutlookAgent and paste the below string and Click OK

1.       "C:\Program Files\Microsoft Office\OFFICE11\OUTLOOK.EXE" /autorun "MacroAgent" (Make sure the Outlook.exe is available in this path. If not change the string accordingly)

11.    Close the registry. Log off from the System.

12.    Login to the system. You should see the Outlook Open by default. If you check the Services you would also see the SQL Server Agent started

Please note that this is an workaround. Basically you should follow it only if you really need it.

Levi Justus
TL, Microsoft SQL Server

Comments (0)

Skip to main content