When I use the query directly it's works, but when I run in it with VBscript this error occurs.
The connection with de DB works.
global_OracleConn = Createobject("ADODB.Connection")
global_OracleConn.Open connectionString
query = "UPDATE DB.TabelX SET X_DT_ = SYSDATE + 360, "_
&"X_Amount_MAX_ID = 100, X_Amount_IN_REQUEST = '1', X_NUM = 15000,"_
&"X_VALUE_LIMIT = 15000, SCORE = 0,
&"WHERE ROW_ID IN (SELECT X_ULTIMA_ID FROM DB.TabelY "_
&"WHERE OU_NUM IN ('"&varID&"'));"
global_OracleConn.Execute(Query)
I tried use others breaklines or put all in one line, but the error still occurs.
There are several issues:
Remove the semicolon at the end from your SQL string
The quoting is wrong. You missed a double quote after SCORE = 0,
Ancient Microsoft ODBC Driver for Oracle is deprecated for ages. Use the ODBC driver from Oracle
Use prepared statement with bind parameters, i.e.
Related
I'm using ADODB.Command to execute prepared statements in Classic ASP, however the number of records being return by MariaDB is incorrect, and I can't figure out why.
The code below gives an example of the problem I'm having:
<%
Dim conn, comm, rs, SQL, SQLparam
set conn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
conn.Open("DSN=localhost")
' Standard execution
SQL = "SELECT * FROM tests WHERE ID > 0"
set rs = conn.Execute(SQL)
response.write "<p>Results: " & uBound(rs.getRows(),2) & "</p>"
' Prepared statement execution
SQL = "SELECT * FROM tests WHERE ID > ?"
SQLparam = 0
Set comm = Server.CreateObject("ADODB.Command")
comm.ActiveConnection = conn
comm.CommandText = SQL
comm.Parameters.Append(comm.CreateParameter("#param",varType(SQLparam),1,250,SQLparam))
set rs = comm.Execute()
response.write "<p>Results: " & uBound(rs.getRows(),2) & "</p>"
set comm = nothing
rs.close() : set rs = nothing
conn.close() : set conn = nothing
%>
Output:
Results: 4433 ' as expected
Results: 10
I feel like I must be missing something obvious. I've played around with the "CreateParameter" settings as outlined by Microsoft here, but the wrong number of records are always returned by MariaDB, never mind what I change.
What's also strange is that if I change the SQL to do a SELECT COUNT, the prepared statement returns the correct count value, it just doesn't return the correct number of rows when I try to select them.
After some further testing this appears to be a driver issue. I'm using MariaDB but with the MySQL ODBC connector (8.0 Unicode Driver). After switching to the MariaDB ODBC connector the prepared statement works as expected. I apologise for not testing further before posting.
I guess MariaDB and the MySQL ODBC connector are incompatible when trying to perform certain database functionality, because up until now I've never had any issues.
I have my query on VB6 which was:
Set Db = DBEngine.OpenDatabase(App.Path & "\sample4nC4.mdb")
Set rs = Db.OpenRecordset("select *from tbl_student;")
Do Until rs.EOF
With ListView1
.ListItems.Add , , rs.Fields("stud_ID")
.ListItems(ListView.ListItems.Count).SubItems(1) = rs.Fields("stud_fname")
.ListItems(ListView1.ListItems.Count).SubItems(2) = rs.Fields("stud_lname")
.ListItems(ListView1.ListItems.Count).SubItems(3) = rs.Fields("stud_address")
.ListItems(ListView1.ListItems.Count).SubItems(4) = rs.Fields("stud_age")
End With
rs.MoveNext
Loop
When I execute this query, there was an error on line 2 says:
Run Time Error '13' Type Mismatch
I really don't get it because when I check the table name, it was correct and yet I cant access the table. Can anybody answer my problem?
Do you have references to ADO and DAO in your project?
If so, look at this Microsoft support article: https://support.microsoft.com/en-us/kb/181542
Do these
Replace your query from 'select *from tbl_student;'
to
'select stud_fname, stud_lname, stud_address, stud_age from tbl_student'
This includes (1. space between '' and 'from' 2. remove ';' 3. specify the field names explicitly)*
Put a breakpoint in the first line your program and step into, if it still fails check which line it's failing.
I have VBScript to drop and create new table in microsoft access.
My vb script is :
Set dbeng = CreateObject("DAO.DBEngine.120")
strMdbFile = "amw\db_amw.accdb"
Set db = dbeng.OpenDatabase(strMdbFile)
strSql1 = "DROP TABLE amw"
StrSql2 = "SELECT * INTO amw FROM MPN_V WHERE (((Format([tgl_bayar],'yyyy')) Between Format(Now(),'yyyy')-2 And Format(Now(),'yyyy')))"
strSql3 = "DROP TABLE UPDATE"
strSql4 = "SELECT * INTO update FROM UPDATE6 WHERE id="1""
db.Execute(strSql1)
db.Execute(strSql2)
db.Execute(strSql3)
db.Execute(strSql4)
when the script runs the line db.Execute(strSql1) and db.Execute(strSql2), no error Happen. but, when the script runs the line db.Execute(strSql3) and db.Execute(strSql4), error Happen : Expected end of statement, code 800A0401, source Microsoft VBScript compilation error. Please correct my Script? thank you verymuch
The problem is with the number of quotes on the last SQL statement.
strSql4 = "SELECT * INTO [update] FROM UPDATE6 WHERE id="1""
If "id" is an integer, use the following:
strSql4 = "SELECT * INTO [update] FROM UPDATE6 WHERE id=1"
If "id" is a string, use the following:
strSql4 = "SELECT * INTO [update] FROM UPDATE6 WHERE id=""1"""
Doubling the quotes are necessary when working with a string within a string.
The below sample ASP classic code that I have modified so it can be run via cscript or wscript, communicating with Oracle 8i and using Oracle ODBC Driver 8.01.07.00 running on Windows 2000, returns a valid shipper_id. This primary key field is populated via a before insert or update trigger (I can include it if necessary, but I have confirmed it works).
However, with Oracle 11, Oracle ODBC driver 11.02.00.03, and Windows Server 2012, only a blank value is returned - why?
Any help that can be provided would be appreciated. Note that I would rather not have to switch to OO4O or use the Oracle Provider for OLE DB unless there is no other option.
Dim strCnxn, cnxn, rs
strCnxn = "DSN=OUR_DSN;uid=OUR_UID;pwd=OUR_PWD"
Set cnxn = Wscript.CreateObject("ADODB.Connection")
cnxn.Open strCnxn
Set rs = Wscript.CreateObject("ADODB.Recordset")
rs.Open "SHIPPER", cnxn, 1, 3, &H0002 'adOpenKeyset, adLockOptimistic, adCmdTable
rs.AddNew
rs("CARRIER_ID") = "13263"
rs("NAME") = "test-shipper"
rs.Update
Wscript.Echo("Shipper ID: " & rs("SHIPPER_ID"))
Wscript.Echo("Carrier ID: " & rs("CARRIER_ID"))
Wscript.Echo("Name: " & rs("NAME"))
rs.Close
Set rs = Nothing
Set cnxn = Nothing
I'm having difficulty using the Update function on a RecordSet object while using the DBISAM 4 ODBC driver. Here is what my code looks like.
dtmNewDate = DateSerial(1997, 2, 3)
MsgBox(dtmNewDate)
'Create connection object & connection string
Set AConnection = CreateObject("ADODB.Connection")
strConnection = "Driver={DBISAM 4 ODBC Driver}; CatalogName=S:\RAPID\Z998\2008; ReadOnly=False"
Aconnection.Mode = adModeReadWrite
AConnection.Open strConnection
'create SQL statement to be run in order to populate the recordset
strSQLEmployeeBDate = "SELECT * FROM Z998EMPL WHERE state = 'NY'"
'Create Recordset object
Set rsRecSet = CreateObject("ADODB.Recordset")
rsRecSet.LockType = 2
rsRecSet.Open strSQLEmployeeBDate, AConnection
While Not rsRecSet.EOF
rsRecSet.Fields("BIRTHDATE").value = dtmNewDate
rsRecSet.Update
rsRecSet.MoveNext
Wend
When I try to execute this code I receive the following error:
"DBISAM Engine Error #11949 SQL Parsing error- Expected ( but instead found = in UPDATE SQL statement at line 1, column 336"
I can't figure out what is causing this error. Does anyone have any ideas as to what is causing it?
DBISAM error messages Check the field name.