Hi, I'm having an issue with HttpJob: the query isn't being sent—it arrives empty on the server side. I've already tested it in the browser, and it does return data in JSON format.
Note: the code was working just fine, but suddenlystops working and I can't for the moment use another connection method such as RDC Connector because it's a huge App
TIA
Note: the code was working just fine, but suddenlystops working and I can't for the moment use another connection method such as RDC Connector because it's a huge App
TIA
B4X:
Dim userconn As String
If (edtport.Text.Trim <> "") Then
userconn = edturl.Text.Trim&":"&edtport.Text.Trim
Else
userconn = edturl.Text.Trim
End If
Dim p As String = edtpass.Text.Trim
Dim md As MessageDigest
Dim ByteCon As ByteConverter
Dim passwordhash() As Byte
passwordhash = md.GetMessageDigest(p.GetBytes("UTF8"),"MD5")
md5string = ByteCon.HexFromBytes(passwordhash)
Dim sql As String = "SELECT id,usuario,nombre,oficina FROM pass WHERE usuario='" & edtuser.Text & "' AND password='" & md5string & "'"
Dim userselect As HttpJob
userselect.Initialize("userselect", Me)
userselect.PostString(userconn & "/prueba.aspx?query=" & sql,"")
'...........................................
Sub JobDone (job As HttpJob)
Log("JobName = " & job.JobName & ", Success = " & job.Success)
If job.Success = True Then
Select job.JobName
Case "userselect"
Dim parserusuario As JSONParser
Dim a As String
parserusuario.Initialize(job.GetString)
Dim rootusuario As List = parserusuario.NextArray
For Each colrootusuario As Map In rootusuario
a = colrootusuario.Get("usuario")
Log("pass: "&a)
Main.idoficina = colrootusuario.Get("oficina")
Next
If (a.Trim=="") Then
Msgbox("Usuario ó Contraseña incorrecta; Verificar" & job.ErrorMessage,"Acceso denegado...")
ProgressDialogHide
Return
End If
'..................................the rest of the code it's too large........
B4X:Dim userconn As String If (edtport.Text.Trim <> "") Then userconn = edturl.Text.Trim&":"&edtport.Text.Trim Else userconn = edturl.Text.Trim End If Dim p As String = edtpass.Text.Trim Dim md As MessageDigest Dim ByteCon As ByteConverter Dim passwordhash() As Byte passwordhash = md.GetMessageDigest(p.GetBytes("UTF8"),"MD5") md5string = ByteCon.HexFromBytes(passwordhash) Dim sql As String = "SELECT id,usuario,nombre,oficina FROM pass WHERE usuario='" & edtuser.Text & "' AND password='" & md5string & "'" Dim userselect As HttpJob userselect.Initialize("userselect", Me) userselect.PostString(userconn & "/prueba.aspx?query=" & sql,"") Sub JobDone (job As HttpJob) Log("JobName = " & job.JobName & ", Success = " & job.Success) If job.Success = True Then Select job.JobName Case "userselect" Dim parserusuario As JSONParser ' Dim u As String Dim a As String parserusuario.Initialize(job.GetString) Dim rootusuario As List = parserusuario.NextArray For Each colrootusuario As Map In rootusuario 'Main.coname = colrootusuario.Get("co_name") 'Main.domic = colrootusuario.Get("agt_domic") 'Main.logo = colrootusuario.Get("reporte") 'Main.logoghost = colrootusuario.Get("reportedir") 'u = colrootusuario.Get("u") a = colrootusuario.Get("usuario") Log("pass: "&a) Main.idoficina = colrootusuario.Get("oficina") Next If (a.Trim=="") Then Msgbox("Usuario ó Contraseña incorrecta; Verificar" & job.ErrorMessage,"Acceso denegado...") ProgressDialogHide Return End If ...................................the rest of the code it's too large........
B4A Log
JobName = userselect, Success = true
pass: null
ResponseError. Reason: , Response: Error en Consulta=
System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at ASP.prueba_aspx.Page_Load(Object sender, EventArgs ec) in h:\root\home\ddefrain-002\www\wh\prueba.aspx:line 27
JobName = rphagent, Success = false
PRUEBA.ASPX - Server Side
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="prueba.aspx.cs" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs ec)
{
using (SqlConnection cn = new SqlConnection("Data Source=SQL511.server.data.net;Initial Catalog=dbase_aa73_wh;User Id=idwh;Password=lepass))
{
using (StreamReader sr = new StreamReader(Request.InputStream, Encoding.UTF8))
{
Response.ContentType = "text/plain";
string c;
c = Request.QueryString["query"]; //for debugging with the browser
//you can set the query by adding the query parameter For ex: http://127.0.0.1/test.aspx?query=select * from table1
if (c == null)
c = sr.ReadToEnd();
try
{
SqlCommand cmd = new SqlCommand(c, cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
while (rdr.Read())
{
Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount);
for (int i =0;i < rdr.FieldCount;i++)
{
d[rdr.GetName(i)] = rdr.GetValue(i);
}
list.Add(d);
}
JavaScriptSerializer j = new JavaScriptSerializer();
Response.Write(j.Serialize(list.ToArray()));
} catch (Exception e)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 500;
Response.Write("Error en Consulta=" + c + "\n");
Response.Write(e.ToString());
}
Response.End();
cn.Close();
}
}
}
</script>
![]()
Last edited: