...

View Full Version : Syntax error - Invalid Character



plasterx
03-13-2006, 03:24 PM
Hi all, can anyone tell me what's wrong with this line of code??

Invalid character
/fyp_actual/sqlconn.asp, line 9, column 7
DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;");
------^

Thanks!

miranda
03-14-2006, 11:58 PM
did you put double quotes around the string?

plasterx
03-20-2006, 08:55 AM
nope that was exactly what i entered - no double quotes. what's wrong with that statement??

DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;

miranda
03-20-2006, 01:25 PM
Well you should have enclosed the string like so
sConn = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"

plasterx
03-23-2006, 03:31 AM
OH well apparently i just did this in my whole file:

<%
driver{ .....}
%>

no wonder it doesn't work.

do you have exactly what is needed to complete the whole thing? I know something like db.open or db.close ... or something =x Or is there a website for me to refer to? =( cos actually i'm trying to access an external database which is stored inside my web hosting company's server ... .so .. i'm not sure if there are any other things i need to take care of?

Thanks so much ....

miranda
03-23-2006, 01:52 PM
Let me rephrase this. ADD the Quotes around the string!!!! the following is a string NOT a variable, therefore it must be enclosed in quotes.

DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;

should be

"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"

IT doesn't matter if it is a remote database server or a database server on the same server that the webserver resides on.

plasterx
03-23-2006, 04:09 PM
ok i think i got it. But currently my file only has this line:
<%
"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"
%>

Do i need to have something like this:

conn = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"
conn.open

or something? Or will those original lines do?

miranda
03-25-2006, 04:07 PM
that is the connection string. You still need to have a connection object and/or a recordset object. below are 3 different examples. In these examples I will get the orderid and also the quantity of widgets sold from the widgets table where the widget color is blue



example using both the connection object and the recordset object


Dim sConnStr, oConn, oRs, sSQL
sConnStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"
Set oConn = Server.CreateOBject("ADODB.Connection")
oConn.Open sConnStr
Set oRs = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM widgets WHERE color = 'blue'"
oRs.Open sSQL, oConn, 0, 1
If Not oRs.EOF Then
While Not oRs.EOF
Response.Write "Order Number: " & oRs("orderID") & "<br>" & vbCrLf
Response.Write "Quantity: " & oRs("quantity") & "<br><br>" & vbCrLF
Wend
End If
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing



Example only using the connection object and it's execute method


Dim sConnStr, oConn, oRs, sSQL
sConnStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"
Set oConn = Server.CreateOBject("ADODB.Connection")
oConn.Open sConnStr
sSQL = "SELECT * FROM widgets WHERE color = 'blue'"
Set oRs = oConn.Execute(sSQL)
If Not oRs.EOF Then
While Not oRs.EOF
Response.Write "Order Number: " & oRs("orderID") & "<br>" & vbCrLf
Response.Write "Quantity: " & oRs("quantity") & "<br><br>" & vbCrLF
Wend
End If
oRs.Close
Set oRs = Nothing
oConn.Close
Set oConn = Nothing



Lastly using only the recordset object


Dim sConnStr, oRs, sSQL
sConnStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=fyp;UID=sa;PWD=;"
Set oRs = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT * FROM widgets WHERE color = 'blue'"
oRs.Open sSQL, sConnStr, 0, 1
If Not oRs.EOF Then
While Not oRs.EOF
Response.Write "Order Number: " & oRs("orderID") & "<br>" & vbCrLf
Response.Write "Quantity: " & oRs("quantity") & "<br><br>" & vbCrLF
Wend
End If
oRs.Close
Set oRs = Nothing



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum