Solved

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

Posted on 2006-11-01
10
374 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now