Database queries dont work properly with long text

Discussion in 'C#' started by ouyeah, Jan 4, 2008.

  1. #1
    Hi, I have a site where an administrator can insert and update news, but it seems recently they are having problems with it.

    It has 3 fields, the titular, a little summary and the body. So, when the body have large text, when I submit the form doesnt return any error messages but it doesnt insert the registry in the database (mdb) neither.

    The thing is that it has worked fine just until some days ago... I have tried to download the database and executing the sql query on my pc and it works, so I dont have any idea.

    Anyone there? :confused:

    Thanks
     
    ouyeah, Jan 4, 2008 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if you can provide the code and the db structure (inc field types) would make it a much less of a stab in the dark exercise
     
    AstarothSolutions, Jan 4, 2008 IP
  3. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #3
    What's the datatype of the field you write the news content in?
    It should be ntext or minimum nvarchar(MAX). But, if it worked before i am pretty sure that it doesn't matter the text length and field datatype.
    However, as Astaroth suggested post the query, code whatever. something that could help us to realize what could be the issue. It's very tricky to find the error/exception when code executes fine but notting happens.
    Would be far easier if an exception was thrown.
    Actually add the Try catch statement around the insert code block and check what will happen. Maybe an exception will be thrown anyway.

    HTH
    Regards :)
     
    yugolancer, Jan 5, 2008 IP
  4. ouyeah

    ouyeah Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The field type of the news is "Memo" (in spanish, dont know if its different in english).

    The piece of code that does the update is:

    
    <% 
    Dim tabla, ID
    tabla = request.QueryString("tabla")
    noticia_ID = request.QueryString("ID")
    %>
    <%
    ' *** Edit Operations: declare variables
    Dim MM_editAction
    Dim MM_abortEdit
    Dim MM_editQuery
    Dim MM_editCmd
    
    Dim MM_editConnection
    Dim MM_editTable
    Dim MM_editRedirectUrl
    Dim MM_editColumn
    Dim MM_recordId
    
    Dim MM_fieldsStr
    Dim MM_columnsStr
    Dim MM_fields
    Dim MM_columns
    Dim MM_typeArray
    Dim MM_formVal
    Dim MM_delim
    Dim MM_altVal
    Dim MM_emptyVal
    Dim MM_i
    
    MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
    If (Request.QueryString <> "") Then
      MM_editAction = MM_editAction & "?" & Request.QueryString
    End If
    
    ' boolean to abort record edit
    MM_abortEdit = false
    
    ' query string to execute
    MM_editQuery = ""
    %>
    <%
    ' *** Update Record: set variables
    
    If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then
    
      MM_editConnection = MM_dbfinestrat_STRING
      MM_editTable = tabla
      MM_editColumn = "ID"
      MM_recordId = "" + Request.Form("MM_recordId") + ""
      MM_editRedirectUrl = ""
      MM_fieldsStr  = "tipo|value|activo|value|titulo|value|resumen|value|noticia|value|imagen|value|posicion|value|imagen2|value|enlace|value|idioma|value"
      MM_columnsStr = "tipo|',none,''|activo|',none,''|titulo|',none,''|resumen|',none,''|noticia|',none,''|imagen|',none,''|posicion|',none,''|imagen2|',none,''|enlace|',none,''|idioma|',none,''"
    
      ' create the MM_fields and MM_columns arrays
      MM_fields = Split(MM_fieldsStr, "|")
      MM_columns = Split(MM_columnsStr, "|")
      
      ' set the form values
      For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
        MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
      Next
    
      ' append the query string to the redirect URL
      If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
        If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
          MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
        Else
          MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
        End If
      End If
    
    End If
    %>
    <%
    ' *** Update Record: construct a sql update statement and execute it
    
    If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then
    
      ' create the sql update statement
      MM_editQuery = "update " & MM_editTable & " set "
      For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
        MM_formVal = MM_fields(MM_i+1)
        MM_typeArray = Split(MM_columns(MM_i+1),",")
        MM_delim = MM_typeArray(0)
        If (MM_delim = "none") Then MM_delim = ""
        MM_altVal = MM_typeArray(1)
        If (MM_altVal = "none") Then MM_altVal = ""
        MM_emptyVal = MM_typeArray(2)
        If (MM_emptyVal = "none") Then MM_emptyVal = ""
        If (MM_formVal = "") Then
          MM_formVal = MM_emptyVal
        Else
          If (MM_altVal <> "") Then
            MM_formVal = MM_altVal
          ElseIf (MM_delim = "'") Then  ' escape quotes
            MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
          Else
            MM_formVal = MM_delim + MM_formVal + MM_delim
          End If
        End If
        If (MM_i <> LBound(MM_fields)) Then
          MM_editQuery = MM_editQuery & ","
        End If
        MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
      Next
      MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId
    
      If (Not MM_abortEdit) Then
        ' execute the update
        Set MM_editCmd = Server.CreateObject("ADODB.Command")
        MM_editCmd.ActiveConnection = MM_editConnection
        MM_editCmd.CommandText = MM_editQuery
    	
    	'Response.write "MM_editQuery" & MM_editQuery
    	'Response.End()
    	
        MM_editCmd.Execute
        MM_editCmd.ActiveConnection.Close
    
        If (MM_editRedirectUrl <> "") Then
          Response.Redirect(MM_editRedirectUrl)
        End If
      End If
    
    End If
    %>
    
    Code (markup):
    Is there any way to debug it? I am new in ASP and I dont have any f*cking idea... :eek:
     
    ouyeah, Jan 7, 2008 IP
  5. teraeon

    teraeon Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    print out the SQL statement before it gets executed basically uncomment these lines:

    Response.write "MM_editQuery" & MM_editQuery
    Response.End()

    and then paste your result here
     
    teraeon, Jan 7, 2008 IP