Solved

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

Posted on 2006-11-01
10
371 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
Comment Utility
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
Comment Utility
let me see the code for recordupdate
0
 
LVL 11

Expert Comment

by:ethoths
Comment Utility
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
 

Author Comment

by:tentavarious
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 35

Expert Comment

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

Author Comment

by:tentavarious
Comment Utility
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
Comment Utility
Did you debug your code? Is it throwing an exception? What's the exception message?
0
 

Author Comment

by:tentavarious
Comment Utility
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
Comment Utility
Make sure there are no unpaired quotes in the error message. To To That use this...

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

7 Experts available now in Live!

Get 1:1 Help Now