locked
System.Runtime.InteropServices.COMException (0xC0048108) when trying to read the emails in a public folder using c# RRS feed

  • Question

  •  

    hi ,

    i am very new to .net world.

    I wrote a code using c# ,which trys to access the emails from exchange server public folder i am getting the below exception:

    System.Runtime.InteropServices.COMException (0xC0048108)
    at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType, Int32 Options)

    and i tried the sample code as shown below. exception is caused at
    recordset open request.


    using System;

    namespace Samples
    {
    class Class1
    {
    static void Main(string[] args)
    {
    try
    {
    ADODB.Connection oCn = new ADODB.Connection();
    ADODB.Recordset oRs = new ADODB.Recordset();

    ADODB.Fields oFields;
    ADODB.Field oField;

    // TODO:
    string sFdUrl = "http://ExchServer/Exchange/UserAlias/Inbox";

    oCn.Provider = "exoledb.datasource";
    oCn.Open(sFdUrl, "", "", -1);

    if(oCn.State == 1)
    {
    Console.WriteLine("Good Connection");
    }
    else
    {
    Console.WriteLine("Bad Connection");
    }


    string strSql;
    strSql = "";
    strSql = "select ";
    strSql = strSql + " \"urnTongue Tiedchemas:mailheader:content-class\"";
    strSql = strSql + ", \"DAV:href\" ";
    strSql = strSql + ", \"urnTongue Tiedchemas:mailheader:content-class\" ";
    strSql = strSql + ", \"DAVBig Smileisplayname\"";
    strSql = strSql + " from scope ('shallow traversal of " + "\"";
    strSql = strSql + sFdUrl + "\"') ";
    strSql = strSql + " WHERE \"DAV:ishidden\" = false";
    strSql = strSql + " AND \"DAV:isfolder\" = false";


    oRs.Open(strSql, oCn,
    ADODB.CursorTypeEnum.adOpenUnspecified,
    ADODB.LockTypeEnum.adLockOptimistic, 1);

    // As an example, you only retrieve the first message.
    // You can use a while loop through each message.

    // Get the first message.
    oRs.MoveFirst();

    // Get Recordset fields.
    oFields = oRs.Fields;

    string sUrl;
    oField = oFields["DAV:href"];
    sUrl = oField.Value.ToString();

    CDO.Message iMsg = new CDO.Message();
    iMsg.DataSource.Open(sUrl, oRs.ActiveConnection,
    ADODB.ConnectModeEnum.adModeReadWrite,
    ADODB.RecordCreateOptionsEnum.adFailIfNotExists,
    ADODB.RecordOpenOptionsEnum.adOpenSource,
    "", "");

    Console.WriteLine("{0}", iMsg.Sender);
    Console.WriteLine("{0}", iMsg.Subject);
    Console.WriteLine("{0}", iMsg.TextBody);

    // Get message fields.
    oFields = iMsg.Fields;


    for(int i = 0; i < oFields.Count; i++)
    {
    oField = oFieldsIdea;
    Console.WriteLine("{0} : {1}", oField.Name, oField.Value);
    }


    oRs.Close();
    oCn.Close();

    oCn = null;
    oRs = null;
    oFields = null;
    oField = null;
    }
    catch (Exception e)
    {
    Console.WriteLine("{0} Exception caught.", e);
    }
    }
    }
    }

    can any one help me please ???
    Thanks
    Anand.
    Tuesday, October 2, 2007 5:12 PM