问题
I need to capture sql message upon successful execution of sql statement using vbscript. Here is my code.
Public Function ExecuteAPI_String(sql_Statement)
Dim num
On Error Resume Next
Set objRecordSet = objConnection.Execute sql_Statement,num,adExecuteNoRecords
If Err.Number <> 0 Then
ExecuteSQLStatement_String = Err.description
objRecordSet.Close
Err.Clear
Else
ExecuteAPI_String = num & "records were affected"
objRecordSet.Close
End If
回答1:
The problem here is the use of On Error Resume Next
because it will cause any statement that errors to be skipped and set the Err
object. If you comment out the On Error Resume Next
you will see the actual error which will be nothing to do with the execution of your SQL query as this line;
Set objRecordSet = objConnection.Execute sql_Statement,num,adExecuteNoRecords
isn't a valid statement as the method needs to be surrounded by brackets like this;
Set objRecordSet = objConnection.Execute(sql_Statement, num, adExecuteNoRecords)
You will also need to make sure that all the values you're passing to the Execute()
method are valid (such as adExecuteNoRecords
being correctly defined).
Once you're sure the line is executing correctly, then you can uncomment the On Error Resume Next
.
来源:https://stackoverflow.com/questions/46595963/return-database-message-on-successful-sql-execution-using-vbscript