Wednesday, March 21, 2012

Problem getting contacts from Exchange

When I attempt to use ADO to get data from any "Contacts" folder I always get...

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="System.Data"
StackTrace:
at System.Data.Common.UnsafeNativeMethods.ICommandText.Execute(IntPtr pUnkOuter, Guid& riid, tagDBPARAMS pDBParams, IntPtr& pcRowsAffected, Object& ppRowset)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
at WinAppExchange.Form1.button1_Click(Object sender, EventArgs e) in C:\Projects\CodeReviewHelper\WinAppExchange\WinAppExchange\Form1.cs:line 31
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at WinAppExchange.Program.Main() in C:\Projects\CodeReviewHelper\WinAppExchange\WinAppExchange\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

string connect = @."Provider=Microsoft.Jet.OLEDB.4.0;Exchange 4.0;MAPILEVEL=Public Folders|All Public\Our Contact List;DATABASE=C:\\Temp\\;";

OleDbConnection connection = new OleDbConnection(connect);

connection.Open();

OleDbCommand command = new OleDbCommand("Select * from [Staff]",connection);

using (OleDbDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection)) // EXCEPTION HERE

{

while (dataReader.Read())

{

System.Diagnostics.Debug.WriteLine(dataReader[0]);

}

}

I've tried the same code against my local stores and I get the same result. However, it works fine for every other folder type, Tasks, notes, inbox, etc. Any ideas?

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=168193&SiteID=1

HTH

No comments:

Post a Comment