Solved

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

Posted on 2006-11-01
10
375 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

861 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