Hi Oleg,
My Component Code goes like htis.
public class WM_Helper
{
public WM_Helper() {}
public static XmlReader GetXMLSet(string SPName)
{
// Creating Connection and Command
XmlReader XmlRdr=null;
string ConString=ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection Con=new SqlConnection(ConString);
SqlCommand Cmd=new SqlCommand(SPName,Con);
Cmd.CommandType=CommandType.StoredProcedure;
try
{
Con.Open();
XmlRdr=Cmd.ExecuteXmlReader();
}
catch
{
throw new Exception(" Error while executing " + SPName);
}
finally
{
//Disposing the Objects
Con.Dispose();
Cmd.Parameters.Clear();
Cmd.Dispose();
}
return XmlRdr;
}
}
My client code is like this
//try
//{
XmlReader red=WM_Helper.GetXMLSet("GetStatusList");
while(red.Read())
{
}
//}
//catch(Exception Ex)
//{
// string str=Ex.Message;
//}
Exception is "Invalid attempt to Read when reader is closed."
Stack Trace is
Invalid attempt to Read when reader is closed.
at System.Data.SqlClient.SqlDataReader.Read()
at System.Data.SqlClient.SqlStream.Read(Byte[] buffer, Int32 offset, Int32
count)
at System.Xml.XmlStreamReader.Read(Byte[] data, Int32 offset, Int32
length)
at System.Xml.XmlScanner.Read()
at System.Xml.XmlScanner.ScanContent()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities()
at System.Xml.XmlTextReader.Read()
at MDB.WebForm1.Button7_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\mdb\webform1.aspx.cs:line 175
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePo
stBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
at System.Web.UI.Page.ProcessRequestMain()
Hope this will help you.
Thanks
Anandraj.A.
"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:Ox**************@TK2MSFTNGP10.phx.gbl...
Anandraj wrote:
So Where I have to close the Reader ? I am calling this Method in my
Client Component. I am getting the Exception only in the client Component.
So am I right that you pass XmlReader client side, read XML from it
successfully and then having exception on Close() method? What's the
exception exactly looks like (along with stack trace, please)?
--
Oleg Tkachenko
XmlInsider
http://blog.tkachenko.com