string connectionString = "server=.;uid=test;pwd=test;database=test";//Your database connection string SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("select * from tablename for xml auto, elements", con); con.Open(); XmlReader reader = cmd.ExecuteXmlReader(); con.Close(); XmlDocument doc = new XmlDocument(); doc.LoadXml(""); XmlNode node = doc.ReadNode(reader); while (node != null) { Console.WriteLine(node.InnerXml); node = doc.ReadNode(reader); } reader.Close(); reader = null; doc = null; doc.Save(Server.MapPath("test.xml"));