Solved

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

Posted on 2006-11-01
10
378 Views
Last Modified: 2008-01-09
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
Comment
Question by:tentavarious
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17850673
the problem could be in recordupdate.

it might return an invalid value or a value with a single quote
0
 
LVL 35

Expert Comment

by:YZlat
ID: 17850677
let me see the code for recordupdate
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17851636
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:tentavarious
ID: 17852214
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
 
LVL 11

Expert Comment

by:ethoths
ID: 17853561
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
 
LVL 35

Expert Comment

by:YZlat
ID: 17858293
in your recordupdate I don't see where do you spesify connection string
0
 

Author Comment

by:tentavarious
ID: 17859282
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
 
LVL 11

Expert Comment

by:ethoths
ID: 17859328
Did you debug your code? Is it throwing an exception? What's the exception message?
0
 

Author Comment

by:tentavarious
ID: 17859438
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
 
LVL 11

Accepted Solution

by:
ethoths earned 125 total points
ID: 17859525
Make sure there are no unpaired quotes in the error message. To To That use this...

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

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question