Hazel Mahmud

Hazel Mahmud

  • 1.4k
  • 315
  • 70k

web.sitemap error

Jan 29 2018 12:33 AM
I get this error when i deploy and run asp .net application in  2 load balance server. The error message is "The process cannot load /inetpub/wwwroot/web.sitemap because its being used by another process". What is the problem actually? Is it at the server or at my coding.?..Please help anyone. TQ so much.
 
My code are as below:.
 
Response.ContentType = "text/xml";
using (XmlTextWriter writer = new XmlTextWriter(Server.MapPath("Web.sitemap"), Encoding.UTF8))
{
writer.WriteStartDocument();
writer.WriteRaw("\n");
writer.WriteStartElement("siteMap");
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
writer.WriteRaw("\n");
writer.WriteRaw("\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", "~/Home.aspx");
writer.WriteAttributeString("title", "Home");
writer.WriteRaw("\n");
writer.WriteRaw("\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", "~/MainPage/main.aspx?system=" + lblsystemID.Text);
writer.WriteAttributeString("title", "");
using (SqlConnection con = ClassConn.GetPortalCon())
{
// con.Open();
// da.SelectCommand = new SqlCommand("SELECT * FROM Menu", con);
SqlCommand cmd = new SqlCommand("ret_Menu", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@userID", nopkj);
cmd.Parameters.AddWithValue("@systemID", lblsystemID.Text);
//cmd.Parameters.AddWithValue("@userID", nopkj);
//cmd.Parameters.AddWithValue("@systemID", lblsystemID.Text);
// da.SelectCommand = new SqlCommand("select dbo.Module.moduleDesc, dbo.Module.moduleID,dbo.Module.modulePath, dbo.Module.systemID, dbo.Module.sort, dbo.Module.thcreate, dbo.[User].userID, dbo.Menu.menuID as menuID, dbo.Menu.menuDesc, dbo.Menu.menuPath, dbo.System.systemDesc from dbo.[User],dbo.[System],dbo.Group_Module,dbo.Module,dbo.Group_Menu,dbo.Menu where userID='" + nopkj + "' and dbo.Group_Module.groupID =dbo.[User].groupID and dbo.Module.moduleID=dbo.Group_Module.moduleID and dbo.Module.systemID=dbo.[System].systemID and dbo.[System].systemID='" + lblsystemID.Text + "' and dbo.Group_Menu.moduleID=dbo.Group_Module.moduleID and dbo.Group_Menu.groupID=dbo.[User].groupID and dbo.Menu.menuID=dbo.Group_Menu.menuID ORDER BY Menu.sort ", con);
SqlDataReader sc = cmd.ExecuteReader();
// SqlDataReader sc = da.SelectCommand.ExecuteReader();
if (sc.HasRows)
{
while (sc.Read())
{
var menuID = sc["menuID"].ToString();
writer.WriteRaw("\n"); writer.WriteRaw("\t\t\t");
writer.WriteStartElement("siteMapNode");
writer.WriteAttributeString("url", sc["menuPath"].ToString());
//writer.WriteAttributeString("title", sc["menuDesc_bi"].ToString() + "/" + sc["menuDesc"].ToString());
//writer.WriteAttributeString("description", sc["menuDesc_bi"].ToString() + "/" + sc["menuDesc"].ToString());
writer.WriteAttributeString("title", sc["menuDesc_bi"].ToString());
writer.WriteAttributeString("menuID", sc["menuID"].ToString());
using (SqlConnection con1 = ClassConn.GetPortalCon())
{
//con1.Open();
// da.SelectCommand = new SqlCommand("SELECT * FROM SubMenu where menuID ='" + menuID + "'", con1);
SqlCommand cmd1 = new SqlCommand("ret_SubMenuSiteMap", con1);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@userID", nopkj);
cmd1.Parameters.AddWithValue("@systemID", lblsystemID.Text);
cmd1.Parameters.AddWithValue("@menuID", menuID);
SqlDataReader sc1 = cmd1.ExecuteReader();
//SqlDataReader sc1 = da.SelectCommand.ExecuteReader();
if (sc1.HasRows)
{
while (sc1.Read())
{
//string menuPath = sc1["subMenuPath"].ToString();
// int duplicateCounter = 0;
//duplicateCounter++;
writer.WriteRaw("\n");
writer.WriteRaw("\t\t\t\t");
writer.WriteStartElement("siteMapNode");
// writer.WriteAttributeString("subMenuID", sc1["MenuIDsub"].ToString());
// writer.WriteAttributeString("subMenuID", sc1["MenuIDsub"].ToString());
//writer.WriteAttributeString("group", sc1["groupID"].ToString());
//if (menuPath == URL)
//{
// string menuURL = "?id=" + duplicateCounter.ToString();
// writer.WriteAttributeString("url", menuPath + menuURL);
// // Response.Redirect("index.aspx?Path=" + menuPath); }
//}
//else
//{
writer.WriteAttributeString("url", sc1["subMenuPath"].ToString());
// }
// duplicateCounter++;
writer.WriteAttributeString("title", sc1["subMenuDesc_bi"].ToString());
writer.WriteAttributeString("description", sc1["subMenuDesc_bi"].ToString());
//writer.WriteAttributeString("title", sc1["subMenuDesc_bi"].ToString() + "/" + sc1["subMenuDesc"].ToString());
//writer.WriteAttributeString("description", sc1["subMenuDesc_bi"].ToString() + "/" + sc1["subMenuDesc"].ToString());
writer.WriteEndElement();
}
}
con1.Close();
con1.Dispose();
}
writer.WriteEndElement();
}
}
con.Close();
con.Dispose();
}
//writer.WriteRaw("\n");
//writer.WriteRaw("\t\t");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
 

Answers (2)