Em client not shutting down cleanly and not able to start back up - How to fix the database

How to fix Em client database issues:

I had an issue were Em client was not properly updating the gui so I closed it out. When I tried to restart it it would not start up. Searched about this and ran across this in the forums:
Download this and try: http://www.emclient.com/tools/DbRepai…
If the problem persist, you may need to delete the database and start fresh. Database location:
C:\Users%Current User%\AppData\Roaming\eM Client (Vista/Win7)
C:\Documents and Settings%Current User%\Application Data\eM Client (XP)

but the checker tool was getting these errors:

System.Data.SQLite.SQLiteException: The database file is locked
database is locked
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader…ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at System.Data.SQLite.SQLiteConnection.Open()
at DbRepair.DbTools.OpenConnection(String fileName)
at DbRepair.Form1.CheckCorruption()
at DbRepair.Form1.Check(Object state)

The first thing is to determine if the process is still active. Task manager did not show it but I used another app called unlocker and found that there were still open handles on the files. I unlocked all the open handles and then tried to rerun the repair utility but still got this:

System.Data.SQLite.SQLiteException: Some kind of disk I/O error occurred
disk I/O error
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader…ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at System.Data.SQLite.SQLiteConnection.Open()
at DbRepair.DbTools.OpenConnection(String fileName)
at DbRepair.Form1.CheckCorruption()
at DbRepair.Form1.Check(Object state)

ok so not the same error but something to look at. I looked around for general info on what to do when an sqlite database is corrupt and how to deal with it and came across this link:

http://community.spiceworks.com/how_t…

not quite what I want but close so:

  1. made a copy of my em client folder

  2. downloaded the sqlite command line interface: http://www.sqlite.org/download.html

  3. Started using it to open the dat files in the directory. I wanted to check the mail first to make sure it was ok

sqlite mail_data.dat
once in I typed:
PRAGMA integrity_check;
as long as it returns with “OK” we are good.
I then typed:
.quit
to exit out of the sqlite command line.

I started doing this for the other folders in the directory:
sqlite mail_fti.dat
sqlite mail_index.dat
and ran the above commands on each database

When I ran this on the privacylistings.dat I noticed there was also a privacylistings.dat-shm and privacylistings.dat-wall file after running the commands however the shm and wall files were no longer there.

This is good. I proceeded with:
atachments.dat
catagory_index.dat
certificate_index.dat
contact_data.dat
contact_index.dat
event_data.dat
even_index.dat
folders.dat
im_data.dat
security_index.dat
task_data.dat
task_index.dat
telemetry.dat
timezones.dat

I did not find one error in any of the databases.

  1. I copied the files back to their original location.

  2. fired up em client but it still did not start. Checked for open file handles but there were none. So I reran the db rebuild utility from above. This time it did not error out right away. It completed the check for inconsistencies and then for corrupt data and found none for either.

  3. After all this em client still would not start so I used process explorer and found the emclient instance and killed it. It was called MailClient.exe and I made sure to select kill process tree.

  4. Then restarted emclient and it found that it had not been shut down correctly and reran it’s check utility which passed again with no issues.

So to sum up.

  1. If you see these do kill the mailclient.exe process making sure to kill the process tree. If the files are still locked then reboot or use a tool like unlocker to unlock them.
  2. Use sqlite command line tool to verify all your db’s
  3. Run the dbrebuild tool provided by emclient in case there is data corruption
  4. Then restart em client.

If we would have needed to there are further steps to take in that we can dump the databases and reimport them. You may loose some small amount of data that way if tables are corrupt but should be able to recover most of it. I’m not sure but maybe the db rebuild tool from emclient would do this for you also.

have a good day all.

hm interesting. Started em up this morning and one of my reminders popped up I tried to click open item and em just froze.

Looking at performance monitor I see em client is showing as
not responding with 21 threads.
0 cpu usage,
No disk i/o,
no network usage,
but MailClient.exe is showing memory usage.

this is a list of the threads:

ntoskrnl.exe!KeWaitForMultipleObjects+0xc0a
ntoskrnl.exe!KeAcquireSpinLockAtDpcLevel+0x732
ntoskrnl.exe!KeWaitForMultipleObjects+0x26a
ntoskrnl.exe!NtWaitForSingleObject+0x41f
ntoskrnl.exe!IoReportTargetDeviceChange+0xe6d
ntoskrnl.exe!KeSynchronizeExecution+0x3a23
wow64cpu.dll!TurboDispatchJumpAddressEnd+0x6c0
wow64cpu.dll!TurboDispatchJumpAddressEnd+0xf5
wow64.dll!Wow64SystemServiceEx+0x1ce
wow64.dll!Wow64LdrpInitialize+0x429
ntdll.dll!RtlIsDosDeviceName_U+0x24c87
ntdll.dll!LdrInitializeThunk+0xe
ntdll.dll!ZwWaitForMultipleObjects+0x15
kernel32.dll!WaitForMultipleObjectsEx+0x8e
mscorwks.dll!CreateApplicationContext+0x7942
mscorwks.dll!CreateApplicationContext+0x756f
mscorwks.dll!CreateApplicationContext+0x7678
mscorwks.dll!CreateApplicationContext+0x770d
mscorwks.dll!DllGetClassObjectInternal+0x5a78
mscorlib.ni.dll+0x1f69df
mscorlib.ni.dll+0x1f6995
System.Windows.Forms.ni.dll+0x722231
System.Windows.Forms.ni.dll+0x204c20
System.Windows.Forms.ni.dll+0x723bb0
System.Windows.Forms.ni.dll+0x723b47
mscorlib.ni.dll+0x217036
mscorlib.ni.dll+0x2204bf
mscorlib.ni.dll+0x216fb4
mscorwks.dll+0x1b4c
mscorwks.dll+0x188d9
mscorwks.dll!CoUninitializeEE+0x1214
mscorwks.dll!CoUninitializeEE+0x1247
mscorwks.dll!CoUninitializeEE+0x1265
mscorwks.dll!GetMetaDataInternalInterface+0x2b536
mscorwks.dll!CoUninitializeEE+0x582f
mscorwks.dll!CoUninitializeEE+0x57cb
mscorwks.dll!CoUninitializeEE+0x56f1
mscorwks.dll!CoUninitializeEE+0x587d
mscorwks.dll!GetMetaDataInternalInterface+0x2b307
mscorwks.dll!GetMetaDataInternalInterface+0x2b3e1
mscorwks.dll!CreateApplicationContext+0x63fa
kernel32.dll!BaseThreadInitThunk+0x12
ntdll.dll!RtlInitializeExceptionChain+0x63
ntdll.dll!RtlInitializeExceptionChain+0x36

the only ones seeming to do anything are the
mscorwks.dll!CreateApplicationContext
and a few others that kind of go back and forth but all the working threads are in
mscorwks.dll

if you need anything else with troubleshooting this please let me know.

interesting this last time. The only thing I did was open up process explorer and start poking around. After that I simply killed the process tree for mailclient.exe.

I did not check the folder or anything but started looking up what I needed to code a fix so that I don’t have to do this manually every time this happens but this time I was curious so I just clicked on emclient and started it again.

It immediately ran the database checker and I just let it run while I was looking into coding a script to fix it. The check finished again and started em client right up and everything is working fine.

Might be good to find out why emclient is getting hung in some of it’s threads though so this is not needed each time.

If you would like me to help with any debugging please let me know. I’m more than willing to help.

Oh and one more thing. My mail dat is over 4GB not sure if this has anything to do with it but the app is not hanging at all in it’s access to database files the hang according to this thread may have something to do with the smtp code in .net:

http://forums.asp.net/t/1423760.aspx

I’m not sure how this fits in with the startup of em client or when it is checking mail since both times I have noticed this it is when it is checking mail. So I would normally think imap or pop but in my case it is imap that I’m using em client with.

here is the pertinent info from that thread:

I was able to solve this. It seems to be very common if you use the SMTP API. Do you have code that looks like this when you send email?

smtpClient.ServicePoint.MaxIdleTime = 1;

smtpClient.ServicePoint.ConnectionLimit = 1;

If so, then it is the MaxIdleTime that is causing the problem. You need to increase it a little. 1 is just not enough time and causes problems.

Thanks.