JET, MAPI and STA

Link. February 7, 2007. Comments [0]. Posted in: .NET

I spent yesterday my fair share of hours trying to get the Exchange/Outlook MAPI Installable ISAM for the JET engine to work through System.Data.OleDb. What we needed to do was pretty simple: Just do a couple of queries on the user's Outlook Inbox folder or Address book and display a few fields from there.

There are quite a few samples and articles about using the Exchange IISAM through jet around, most of them old samples in VB6 using DAO and ADO (understandably). And they actually worked. However, when I tried to do the same from .NET I kept getting the following exception:

System.Data.OleDb.OleDbException: There are no MAPI clients installed on this machine. Install a MAPI client (like Outlook) on this machine.

After much fiddling and much frustration, I figured out what the problem was: The Exchange/Outlook IISAM engines need to be called from an STA Thread. That was not a problem for the many VB6-based samples because VB code was always in the STA, but in .NET threads by default are joined to the process' MTA.

Just thought I might save someone a little frustration by point this out. Boy, I had almost forgotten how "fun" COM threading models were!



Comments are closed.

Syndicate

About

Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...

tomasrestrepo @ twitter My Flickr photostream My saved links on delicious My Technorati Profile

email: tomas@winterdom.com
msn: tomasr@passport.com

View my profile on LinkedIn

MVP logo

Ads


Categories

Statistics

Total Posts: 1041
This Year: 111
This Month: 1
This Week: 0
Comments: 819

Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 2.2.8279.16125

Sign In