0
votes

I am trying to insert data into a SQL database using a VBScript, but the script will not compile due to an invalid character (the double quote before InitialCatalog).

I have checked the encoding (ANSI), I have tried deleting and retyping the quote to make sure it's not a "curly quote", I have added additional spaces to make sure that the error follows the quotation mark, I have tried replacing the quote with chr(34) and I have even created a new file and retyped the entire script to make sure there was no copy and paste related errors. I am stumped. Here is the entire script:

Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider=SQLOLEDB;" & _
"Data Source=******;" & _
"Trusted_Connection=Yes;" & _ "InitialCatalog=ERO;" & _
"User ID=*****;Password=*****;"

objRecordSet.Open "INSERT INTO Documents (RONumber, Description, FileName)" &  _
    "VALUES ('12345', 'RO', objArgs(0))", _
        objConnection, adOpenStatic, adLockOptimistic

Thanks in advance for any help!

1
Did you ever get this solved?Ann L.

1 Answers

2
votes

I think the problem is the "_" before the double-quote, not the double-quote. You need a _ at the end of a line you intend to continue on the next line, but (unless I much mistake) anywhere else, it's a syntax error.

By the way, your SQL is probably going to fail because, rather than passing the value of objArgs(0), you've baked the string literal "objArgs(0)" into the SQL. SQL isn't going to know what that is.