Socrata query length issue - query-string

I am developing a MVC Web app with socrata private dataset as my backend.
I am having some issues while passing more filters in the querystring to fetch data from socrata.
my soql is
resource/xxxx-xxxx.json?$select=pais_extendido,var_descripcion,rango_edad,genero,zona_geografica,tam_de_firma,quintil_ingreso_laboral,quintil_ingreso_total,anio2,tipo_variable,valor&$where=pais_extendido ='Bolivia' AND (var_descripcion ='Personas+que+no+estudian+ni+trabajan+(en+%25)' OR var_descripcion ='Personas+que+no+estudian+ni+trabajan+(en+niveles)' OR var_descripcion ='A%c3%b1os+de+educaci%c3%b3n+promedio' OR var_descripcion ='Personas+con+educaci%c3%b3n+terciaria+t%c3%a9cnica+(en+%25)' OR var_descripcion ='Personas+con+educaci%c3%b3n+terciaria+t%c3%a9cnica+(en+niveles)' OR var_descripcion ='Poblaci%c3%b3n+ind%c3%adgena+o+afro-descendiente+(en+niveles)' OR var_descripcion ='Poblaci%c3%b3n+ind%c3%adgena+or+afro-descendiente+(en+%25)' OR var_descripcion ='Poblaci%c3%b3n+total' OR var_descripcion ='Poblaci%c3%b3n+en+edad+de+trabajar+(en+%25)' OR var_descripcion ='Poblaci%c3%b3n+en+edad+de+trabajar+(en+niveles)' OR var_descripcion ='Indicador+de+pobreza+(50%25promedio%2c+2011PPP%2c+escala+antigua+OCDE)' OR var_descripcion ='Indicador+de+pobreza+(60%25promedio%2c+2011PPP%2c+escala+antigua+OCDE)' OR var_descripcion ='Indicador+de+pobreza+extrema+(USD+2.5%2c+2011PPP)' OR var_descripcion ='Indicador+de+pobreza+extrema+(USD+2.5%2c+2011PPP%2c+escala+antigua+OCDE)' OR var_descripcion ='Indicador+de+pobreza+moderada+(USD+4%2c+2011PPP)' OR var_descripcion ='Indicador+de+pobreza+moderada+(USD+4%2c+2011PPP%2c+escala+antigua+OCDE)' OR var_descripcion ='Indicador+de+clase+alta+(USD+50%2b%2c+2011PPP)' OR var_descripcion ='Indicador+de+clase+media+(USD+10-50%2c+2011PPP)' OR var_descripcion ='Indicador+de+poblaci%c3%b3n+vulnerable+(USD+4-10%2c+2011PPP)' OR var_descripcion ='Formalidad+(1)%3a+Trabajadores+activos+cotizantes+a+la+seguridad+social+(en+%25+de+la+poblaci%c3%b3n+econ%c3%b3micamente+activa)' OR var_descripcion ='Formalidad+(1)%3a+Trabajadores+activos+cotizantes+a+la+seguridad+social+(en+niveles)' OR var_descripcion ='Formalidad+(2)%3a+Ocupados+cotizantes+a+la+seguridad+social+(en+%25+de+la+poblaci%c3%b3n+ocupada)' OR var_descripcion ='Formalidad+(2)%3a+Ocupados+cotizantes+a+la+seguridad+social+(en+niveles)' OR var_descripcion ='Formalidad+(3)%3a+Asalariados+cotizantes+a+la+seguridad+social+(en+%25+del+total+de+asalariados)' OR var_descripcion ='Formalidad+(3)%3a+Asalariados+cotizantes+a+la+seguridad+social+(en+niveles)' OR var_descripcion ='Formalidad+(4)%3a+Trabajadores+independientes+cotizantes+a+la+seguridad+social+(en+%25+del+total+de+trabajadores+independientes)' OR var_descripcion ='Formalidad+(4)%3a+Trabajadores+independientes+cotizantes+a+la+seguridad+social+(en+niveles)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+declara+un+monto+recibido+por+pensi%c3%b3n+contributiva+(en+%25)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+declara+un+monto+recibido+por+pensi%c3%b3n+contributiva+(en+niveles)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+declara+un+monto+recibido+por+pensi%c3%b3n+no+contributiva+(en+%25)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+declara+un+monto+recibido+por+pensi%c3%b3n+no+contributiva+(en+niveles)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+declara+un+monto+recibido+por+pension+contributiva+o+no+contributiva+(en+%25)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+declara+un+monto+recibido+por+pension+contributiva+o+no+contributiva+(en+niveles)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+trabaja+y+recibe+pensi%c3%b3n+(en+%25)' OR var_descripcion ='Personas+de+65+o+m%c3%a1s+a%c3%b1os+que+trabaja+y+recibe+pensi%c3%b3n+(en+niveles)' OR var_descripcion ='Desempleados+aspirantes+(en+%25)' OR var_descripcion ='Desempleados+aspirantes+(en+niveles)' OR var_descripcion ='Desempleados+cesantes+(en+%25)' OR var_descripcion ='Desempleados+cesantes+(en+niveles)' OR var_descripcion ='Desempleados+de+larga+duraci%c3%b3n+(en+%25)' OR var_descripcion ='Desempleados+de+larga+duraci%c3%b3n+(en+niveles)' OR var_descripcion ='Desocupados+con+educaci%c3%b3n+terciaria+t%c3%a9cnica+(en+%25)' OR var_descripcion ='Desocupados+con+educaci%c3%b3n+terciaria+t%c3%a9cnica+(en+niveles)' OR var_descripcion ='Personas+que+no+estudian+ni+trabajan+ni+buscan+trabajo+(en+%25)' OR var_descripcion ='Personas+que+no+estudian+ni+trabajan+ni+buscan+trabajo+(en+niveles)' OR var_descripcion ='Poblaci%c3%b3n+desocupada+(en+%25)' OR var_descripcion ='Poblaci%c3%b3n+desocupada+(en+niveles)' OR var_descripcion ='Promedio+de+duraci%c3%b3n+en+el+desempleo+(en+meses)') AND rango_edad ='Edad+15+a+64+a%c3%b1os' AND genero ='Ambos' AND zona_geografica ='Total' AND tam_de_firma ='No+aplica' AND quintil_ingreso_laboral ='Todos' AND quintil_ingreso_total ='Todos' AND (anio2 ='1990' OR anio2 ='1991' OR anio2 ='1992' OR anio2 ='1993' OR anio2 ='1994' OR anio2 ='1995' OR anio2 ='1996' OR anio2 ='1997' OR anio2 ='1998' OR anio2 ='1999' OR anio2 ='2000' OR anio2 ='2001' OR anio2 ='2002' OR anio2 ='2003' OR anio2 ='2004' OR anio2 ='2005' OR anio2 ='2006' OR anio2 ='2007' OR anio2 ='2008' OR anio2 ='2009' OR anio2 ='2010' OR anio2 ='2011' OR anio2 ='2012' OR anio2 ='2013' OR anio2 ='2014') AND tipo_variable ='niveles%2c+%23'&$limit=10000
I have tried the IN operator but since its is derived dataset its not working.
Can u help me optimize this query?
Is there any limitaion in the querystring length that should be send across browser or any limitations provided in the socrata end to limit the querystring length?

Related

Read MS Word file page by page with header and footer using OpenXml and iTextSharp

I'm new in OpenXml and recently started development using OpenXml with ASP.Net(C#/Vb).
I want to read MS Word file page by page with header and footer using OpenXml and then write those pages to pdf file using iTextSharp.
Code for Reference:
Dim fileName As String = "D:\With_Header.docx"
Dim body As Body
Dim contentOfFile As String = String.Empty
Dim pdfDoc As New iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 30, 30)
Dim pdfWriter As PdfWriter = pdfWriter.GetInstance(pdfDoc, fs)
Using strm As Stream = File.Open(fileName, FileMode.Open)
Using doc As WordprocessingDocument = WordprocessingDocument.Open(strm, False)
body = doc.MainDocumentPart.Document.Body
contentOfFile = body.InnerText
pdfDoc.Add(New iTextSharp.text.Paragraph(contentOfFile))
pdfDoc.Close()
pdfWriter.Close()
End Using
End Using

Set splitlate=false on gridview itextsharp

Here is the layout of my page that I am exporting:
-------------------------------
' Text text text '
' '
' Gridview '
' '
' Text text text '
--------------------------------
Here is my table after rendering to HTML
<table cellspacing="0" id="mytest_gvMain" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th scope="col">Item</th>
<th scope="col">Description</th>
<th scope="col">Quantity</th>
<th scope="col">Unit</th>
<th scope="col">Rate</th>
</tr>
<tr>
</tr>
</tbody>
</table>
As you see the gridview is in the middle of the page. Because the gridview can of any size expanding to different pages, I would like to set SplitLate = false, so the row stays together. Now some of the text in the last row is on page 1 and the some of it on the first row of page 2. Please have a look at this image .
Some data on last row of page 5 and some on first row of page 6. I have read some documents suggesting document.add(table) but that will add the table to the end of my document. Is there a way I set SplitLate on the gridview itself?
Based on Chris suggestion, I have updated my code to use xmlworker based on this link Cannot get CSS to work in iTextSharp (5.4.3) when making pdf.
Using input As New MemoryStream(bytes, False)
Dim ms As New MemoryStream()
Dim document As New iTextSharp.text.Document(iTextSharp.text.PageSize.LETTER, 36, 36, 36, 36)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, ms)
writer.CloseStream = False
document.Open()
Dim htmlContext As HtmlPipelineContext = New HtmlPipelineContext(Nothing)
htmlContext.SetAcceptUnknown(True)
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory())
Dim cssResolver As ICSSResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(False)
cssResolver.AddCssFile(HttpContext.Current.Server.MapPath("/assets/css/pdf.css"), True)
Dim pipeline As New CssResolverPipeline(cssResolver, New HtmlPipeline(htmlContext, New PdfWriterPipeline(document, writer)))
Dim pdfworker As New XMLWorker(pipeline, True)
Dim p As New XMLParser(True, pdfworker, New System.Text.UTF8Encoding)
Try
'p.AddListener(pdfworker)
'p.Parse(input, Encoding.UTF8)
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, input, New FileStream(HttpContext.Current.Server.MapPath("~/assets/css/pdf.css"), FileMode.Open, FileAccess.Read))
Catch
Finally
pdfworker.Close()
End Try
document.Close()
ms.Position = 0
Response.Buffer = True
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=preview.pdf")
Response.BinaryWrite(ms.GetBuffer())
Response.Flush()
End Using
Any help appreciated.

Error in converting aspx page to html (itextsharp 5.0.6)

I use this code to convert my aspx page to pdf using itextsharp 5.0.6:
Using ms = New MemoryStream()
Dim Html As String = vbCr & vbLf & "<h1>h1</h1>" & vbCr & vbLf & "<p class=""bo"">A paragraph</p> " & vbCr & vbLf & "<ul> " & vbCr & vbLf & "<li>one</li> " & vbCr & vbLf & "<li>two</li> " & vbCr & vbLf & "<li>three</li> " & vbCr & vbLf & "</ul>"
Dim Html1 As String = RenderControlToString(Page)
Dim styles As New StyleSheet()
styles.LoadStyle("bo", "size", "10")
styles.LoadTagStyle(HtmlTags.H1, HtmlTags.FONT, "59")
styles.LoadTagStyle(HtmlTags.H1, HtmlTags.COLOR, "#ff0000")
styles.LoadTagStyle(HtmlTags.UL, HtmlTags.INDENT, "10")
styles.LoadTagStyle(HtmlTags.LI, HtmlTags.LEADING, "16")
Using document As New Document(PageSize.A4, 10.0F, 10.0F, 100.0F, 0.0F)
document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())
PdfWriter.GetInstance(document, ms)
document.Open()
document.Add(New Paragraph("this is atest"))
document.Add(New Paragraph("this is a test"))
Dim strB As New StringBuilder(Html1)
Using sReader As TextReader = New StringReader(Html1.ToString())
Dim list As List(Of IElement) = HTMLWorker.ParseToList(sReader, styles)
For Each elm As IElement In list
document.Add(elm)
Next
End Using
End Using
End Using
However I kept getting error on this line saying object reference not set to an instance of an object:
Dim list As List(Of IElement) = HTMLWorker.ParseToList(sReader, styles)
If I changed from variable Html1 to Html in this line of code, it is working fine.
Using sReader As TextReader = New StringReader(Html1.ToString())
Any idea how I can fix this error? Here is the function:
Private Function RenderControlToString(control As Control) As String
Dim sb As New StringBuilder()
Dim sw As New StringWriter(sb)
Dim writer As New HtmlTextWriter(sw)
control.RenderControl(writer)
Return sb.ToString()
End Function
Thanks for your help.
(comment moved to answer)
iTextSharp's HTMLWorker has known problems with <hr> tags. The short term solution is to just remove those tags but the long term solution is to switch to XMLWorker which supports those tags and is actively being developed and maintained.

Updating multiple tables using .NET and Access

Really sorry if this has been asked 10000 times but i couldn't find anything about it.
I'm making backup copies of database tables from a dev site to a live site and i am using this code to do so but i have another 10 tables to copy over and I'm sure there must be an easier way that this?
Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../../_db/db.mdb") & "")
AccessConn.Open()
Dim AccessCommand As New System.Data.OleDb.OleDbCommand("DELETE * FROM news", AccessConn)
AccessCommand.ExecuteNonQuery()
Dim AccessCommand2 As New System.Data.OleDb.OleDbCommand("INSERT INTO news SELECT * FROM news_dev WHERE isapproved", AccessConn)
AccessCommand2.ExecuteNonQuery()
Response.Write("News Updated")
Response.Write("<br />")
Dim AccessCommand3 As New System.Data.OleDb.OleDbCommand("DELETE * FROM pages", AccessConn)
AccessCommand3.ExecuteNonQuery()
Dim AccessCommand4 As New System.Data.OleDb.OleDbCommand("INSERT INTO pages SELECT * FROM pages_dev WHERE isapproved", AccessConn)
AccessCommand4.ExecuteNonQuery()
Response.Write("Pages Updated")
Response.Write("<br />")
AccessConn.Close()

URL error for some files,The requested document was not found on this server

Hi every one i have a funny problem. i want to read an URL from a database ,but it give me this error for some videos! not all of them!(the error is The requested document was not found on this server. )In local network it work fine and all the movies are playing!, but when i upload the site in internet, the error occurs.
any idea?
and here is the fine URL:
http://babakpirmoradi.ir/User/videos/Ostadpirmoradi2.flv
here is the url that gives error:
http://babakpirmoradi.ir/User/videos/418619301525735_21489.mp4
here is my code:
(GetUrl() pass the URL dynamically)
<div style="width: 650px">
<video id="example_video_1" align="center" class="video-js" controls="controls"
height="442" preload="auto" width="590">
<source src=<%=GetURL()%> type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'/>
</video></div>
here is my url cod:
public string GetURL()
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(connStr);
SqlCommand sqlcmd = new SqlCommand();
sqlconn.Open();
sqlcmd = new SqlCommand("SELECT Video FROM AddVideo where ID=#ID", sqlconn);
sqlcmd.Parameters.AddWithValue("#ID", Request.QueryString["ID"]);
string URL = ((string)sqlcmd.ExecuteScalar()).ToString();
return URL;
}
This is happening because the video actually does not exists or we have no rights to access it:

Resources