Tag Archives: email

Solving "Unexpected Store Error" in Exchange

Getting a weird COM Exception with the cryptic ID 0x8055001E?

We’ve been struggling with this problem for over a year now, and we finally have a solution.

We have some critical code that is contacting Exchange server via COM Interop and CDOEX.DLL to read some inboxes and process e-mails. About once a month or so, we get this error:

System.Runtime.InteropServices.COMException (0x8055001E): Unexpected
store error: %1!d! (0x%1!8.8x!)
   at ADODB.RecordsetClass.Open(Object Source, Object
ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType,
Int32 Options)
   at MessageService.Exchange.ExchangeClient.Connect(String folderUrl,
String userId, String password, Boolean useHttp)

After this point, restarting our software does not help. The only recourse is to restart the Exchange store completely. Did I mention that our software needs to run 24/7/365 with no downtime (a few minutes here and there are acceptable)?

So about once a month, I get a message on my phone, I log into the server, reboot Exchange, and all is well.

Searching on Google revealed nothing at all. Until recently.

I now believe the problem was we were checking two e-mail accounts back-to-back, in a loop like this (highly simplified):

while (running)
{
    CheckAccount1();
    CheckACcount2();
    Thread.Sleep(60000);
}

Apparently, there is some bug in the CDO COM components’ code that will cause errors if you reconnect too fast. Occasionally, the Exchange code must have completed so quickly that it didn’t provide enough time for the COM components to clean up properly before the next solution attempt. Solution?

while (running)
{
    CheckAccount1();
    Thread.Sleep(5000);
    CheckAccount2();
    Thread.Sleep(60000);
}

We implemented that change on a staging server that was also experiencing this problem and haven’t had a single reoccurrence since. The fix will be going into production very soon. No more 2AM alerts!


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

20 Things to do when the Internet goes down

Even if the Internet connection goes out, your computer does not become a dumb brick. There were days these last few days where I didn’t bother turning it on. Then I realized all the things I could still do.

(My home Internet connection finally came back this morning. I’m bit upset that they didn’t figure it out earlier. It turned out that the first technician grossly misdiagnosed the problem. He put in an order for a new drop to be put in. Turned out it was just a broken modem. Why didn’t they try that earlier? Worse, why didn’t I think of it earlier. To be honest, I did think of it, but didn’t push it. Now I just need to get my money back from Comcast.)

Without further ado, here’s my suggestions for what to do when the Internet goes out:

On the computer:

  1. Organize photos in Picasa – I have nearly 6,000 photos on my computer. Many of them need to be deleted, organized, tagged, labeled, e-mailed, etc. (Yes, e-mailed–I can queue them in Outlook until the connection comes back).
  2. Organize My Documents – I’ve let My Documents folder get very messy. Lots of files that don’t need to be there anymore. Others need to be filed, or re-filed.
  3. Organize e-mail – I’ve got hundreds of folders in Outlook. I’ve tried to keep my Inbox empty and put things into @Action, @Someday, or @WaitingFor folders before they find a permanent home, but sometimes it still gets out of hand.
  4. Organize and fill in information in Windows Media Player. I still have music tagged with the wrong genre…
  5. Program. I’ve got two major programming projects I’m working on. They don’t depend on the Internet. The Internet is NICE if you need to learn something, but there’s always plenty of stuff to do that doesn’t require it. Write unit tests, run code coverage, design graphics, do all the other stuff if you must.
  6. Write e-mails to family. Long ones. Your mom will thank you.
  7. Catch up on podcasts. I got through ten episodes of Ask a Ninja, and nearly all backlogged podcasts. Now I’ll have a flood when I sync tonight.
  8. Write blog entries. I use Windows Live Writer. I should have done more of this.
  9. Play a game.
  10. Better, write a game.
  11. Setup appointments and events in Outlook for the next year.
  12. Read some classic programming texts.
  13. General computer maintenance. Defrag your disk, delete temp files, delete old installation files you haven’t used in 5 years (yes, I have some of those…). Use DiskSlicer to find where your space is going.
  14. Do long-avoided projects. I have approximately 20 hours of audio I need to edit and split into tracks. I’ve been putting it off for a very long time.

Off the Computer:

  1. Practice the piano.
  2. Read books. I’ve just started Cryptonomicon by Neal Stephenson. Very good, so far. Go buy it. If you’re a geek, you’ll like it. How can you not love a 2 page diversion into the mathematics of when a bike chain will interfere with a broken spoke and fall off? Other than the geekiness, it’s a good story.
  3. Learn to cook a new dish.
  4. Do crosswords.
  5. Exercise.
  6. Relax.

Or just go to the library and use the Internet. I only did this a few times, despite it being within walking distance from where I live.

Technorati Tags: ,,,,,,


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Importance of disposing MailMessage objects

Always, always, always follow the suggested usage patterns of disposable objects. I had a strange problem recently where e-mail messages with attachments weren’t releasing the lock on the files for a long time. I was using the System.Net.Mail namespace, specifically the Attachment and MailMessage classes.

Disposable objects represent resources not directly under control by the CLR–and this includes SMTP connections. By not calling dispose, the mail message was just sitting around, not getting sent. Why this is the case when I explicitly call SmtpClient.Send is unclear. The main symptom of this problem was that files that I attached to the e-mail message were still locked when I tried to delete them immediately after the send.

Something like this will do:

using (MailMessage msg = new MailMessage()) 
{ 
    msg.Attachments.Add(...); 
    client.Send(msg); 
}

Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Changes in .Net 1.1. and 2.0 E-Mail classes

I recently (re?)learned a harsh lesson at work. We migrated a critical application’s e-mail client code to use System.Net.Mail‘s classes instead of those in the deprecated System.Web.Mail.

After doing this, we immediately had three problems, mostly with the Attachment class:

  1. Our automated test software could no longer read the attachments
  2. Attachments started having names of Directory_Directory_FileName (they were just Filename)
  3. The software could no longer delete the attachment files from disk after they were e-mailed (the file was still in use).

With problem 1, it turned out that the default encoding in the old MailAttachment class was 7Bit and the test program (which I didn’t write) was directly scraping the mail queue (on a Linux system) and reading the encoded text, looking for recognizable tokens. The new class’s default encoding was Base64–gibberish, to this test¬†program. It wouldn’t really matter to our end-users, but the taking the “easy” way out in writing the test program locked us into an encoding. It just so happens, though, that 7Bit encoding is preferable in our circumstances, even for end-users (Base64 adds significant e-mail overhead–some of our users pay by kilobyte).

The 2nd problem took me a little longer to figure out. At first I thought it was a bug in the attachment naming code, but I couldn’t find anything either in code or the file system. It turns out that the name of the file that the Attachment class is giving includes the directory structure in the name–this seems quite odd–I mean, how often do you want a file name like that? So I manually set the ContentDisposition.FileName property to be just the filename.

I still haven’t completely figured out #3. I think it’s because the MailMessage class is locking the file during send, and not releasing it as early as the old class. In any case, I haven’t directly solved the problem, just come up with a semi-elegant workaround.

Lessons:

  1. Don’t assume default settings are the same across framework upgrades.
  2. Build unit tests to test the assumed stuff–even the stuff controlled by the framework. Don’t assume it’s doing exactly what you want with default settings.
  3. Most importabtly, if your functionality depends on specific settings, then explicitly specify them–don’t ever leave them to chance.

Thankfully, these were relatively easy to diagnose and caused minimal to moderate impact.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order:

Free Code Here!

I just received this hilarious message: 

Thanks, you *****, for not responding to my Prim’s e-mail, and may you be cursed with the worst of success in Computer Science.

Sincerely,

Michael

Every once in a while I get requests from people asking me for completed code. The purpose of my articles (and this blog) is to aid understanding, not provide wholesale code. My job keeps me plenty busy, I receive a LOT of e-mails every day, and I probably don’t have the fully-functional, runnable code that people are looking for anyway, when they can probably find it on the Internet.

That said, I have received numerous comments, specific questions, disagreements, kudos, and suggestions that I have warmly responded to.


Check out my latest book, the essential, in-depth guide to performance for all .NET developers:

Writing High-Performance.NET Code, 2nd Edition by Ben Watson. Available for pre-order: