Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

unterminated string constant error when registering startup script from asp.net

Experts, I keep getting the unterminated string constant error when I try to register a startup script from my code behind file.  I know its a syntax error and should be an easy fix, but I am not sure what it is.  Take a look at my, can anyone see what I am missing


'Cannot get this to work
  Dim finalstr As String
                str = recordupdate("Select records from table") ' this is a function that returns a message if the sql went through
                finalstr = "<script> alert('" & str & "');</script>"
                Me.RegisterStartupScript("anything", finalstr)

'This works fine

  str = "<script> alert('Maintenance number required!');</script>"
            Me.RegisterStartupScript("anything", str)

I get the error when I try to pull the message from a function.
0
tentavarious
Asked:
tentavarious
  • 4
  • 3
  • 3
1 Solution
 
YZlatCommented:
the problem could be in recordupdate.

it might return an invalid value or a value with a single quote
0
 
YZlatCommented:
let me see the code for recordupdate
0
 
ethothsCommented:
str update contains either a ' or a " in the return as on O'Riely.

You need to do a string.replace on these characters and replae them with double chars...

str=str.Replace("'", "''")

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
tentavariousAuthor Commented:
Function recordupdate(ByVal ssql As String) as string
        Dim dbcomm As New OracleCommand
        Dim message As string
        Try
            If objconn.State = ConnectionState.Open Then
                objconn.Close()
            End If
            dbcomm.CommandText = ssql
            dbcomm.CommandType = CommandType.Text
            dbcomm.Connection = objconn
            objconn.Open()
            dbcomm.ExecuteNonQuery()
            message = "Record added!!"
        Catch ex As Exception
            message = ex.message
        End Try
        If objconn.State = ConnectionState.Open Then
            objconn.Close()
        End If
        Return message
    End Function
0
 
ethothsCommented:
Sounds like it's throwing an exception in the database routines and there is a ' in the exception message (ex.message). Best way to find out is to put a break point at the start of the function and step it through line by line. If you switch on the autos window you'll be able to see the exception message. I'm assuming that the objconn is a class level object and that it's connection string is set elsewhere?

Also, try restructuring you code like this...

Function recordupdate(ByVal ssql As String) as string
        Dim dbcomm As New OracleCommand
        Dim message As string
        Try
            dbcomm.CommandText = ssql
            dbcomm.CommandType = CommandType.Text
            dbcomm.Connection = objconn
            objconn.Open()
            dbcomm.ExecuteNonQuery()
            message = "Record added!!"
        Catch ex As Exception
            message = ex.message
        Finally
            If objconn.State = ConnectionState.Open Then
                objconn.Close()
            End If
        End Try
        Return message
    End Function


There's no need to close the connection at the start of the method and putting it in the finally clause ensure it will always run (even if an error occurs).

0
 
YZlatCommented:
in your recordupdate I don't see where do you spesify connection string
0
 
tentavariousAuthor Commented:
Yes connection string is set else where in a different class, because I connect to different database types and I use it on multiple web pages.  The connection string is specified on the top and it works fine so I didnt think it useful to show it.
0
 
ethothsCommented:
Did you debug your code? Is it throwing an exception? What's the exception message?
0
 
tentavariousAuthor Commented:
Yeah, it throws the error when I try to create a dublicate primary key.  It looks something like this, I dont have the actual Ora error code but the message is similiar.
ex.message ="Ora error:09090 string constant exists in table "
0
 
ethothsCommented:
Make sure there are no unpaired quotes in the error message. To To That use this...

 message = ex.message.Replace("'","''").Replace(""",""""")
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now