Currentdb.Execute (Database.Execute) not working or throwing errors - ms-access

I am trying to insert 2 values from variables into a table via SQL, the code finishes without error but the entries are not showing up in the table.
I tried executing the code within the immidate window but that gave me an error about my brackets (Don't really know how to enter the prompt properly there), so I changed my query from having variables to having set values to insert, but it still does not work nor does it give an error.
I made sure I had no "On Error" in my code and tried to build in an error manually. Syntax errors are shown as usual so I am assuming that everything is fine with error messages.
'Table Columns: ID, ProjectID, Versionnumber
SQL = "INSERT INTO tblVersion " & _
"(ProjectID, Versionnumber) " & _
"VALUES (1, 'v3.0');"
Currentdb.Execute SQL
I expect the Value to be shown when I open the table. Instead, nothing happened at all.

CurrentDb.Execute doesn't raise all errors by default. It will just silently fail, without letting you know the query was unsuccessful, independent of any On Error statements.
As far as I know, all errors that can be generated at compile time (syntax errors, invalid table names or field names) do get raised, while run-time errors (violated constraints, duplicate primary keys, etc.) don't get raised.
To get all errors, use dbFailOnError. This will also cause the entire query to fail if a single operation encounters an error (e.g. one row violates a constraint), while without it only the failed operation won't go through.
So, in summary, use this:
Currentdb.Execute SQL, dbFailOnError

Related

How to fix error - "No disconnected record set is available for the specified SQL statement."

I am executing a stored procedure to collect the data set into a variable of object type. The stored procedure has 2 parameters and works fine. When I use the same stored procedure in 'execute Sql task' in ssis I get the error message as "[Execute SQL Task] Error: Executing the query "EXEC [dbo].proc_procname]
#CD1 = ?, #C..." failed with the following error: "No disconnected record set is available for the specified SQL statement.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
The input parameter was defined as string, removal of quotes from value of that parameter, resolved the error.
I was also getting this error. In my case it was a large amount of inline T-SQL.
At the top it had a use and a few set statements with go in between. I commented out all the Go statements and that solved my issue.

Error in mysql database in Qt

I wrote this sql codes in qt5 in ubuntu. I want to update a table. But I received following error:
QSqlError(1065, "QMYSQL: Unable to execute query", "Query was empty")
This is my sql code:
query4.prepare("update food_main set cost=:material_cost,"+material+"=:material_num where name='"+material_name+"'");
query4.bindValue(":material_cost",material_cost);
query4.bindValue(":material_num",material__num);
query4.exec();
I must say that my table updates every time I run my code but I have the error too. Table and columns and variables were made in right method. What should I do?

MS Access crashes on error

I wrote a little SQL command to correct a field in a table. Since it was so small (and maybe I got a little arrogant) I didn't run it even once, and just put it into an update package for a different user.
Dim SQL As String
Dim rs As DAO.Recordset
On Error GoTo errhandler
SQL = "UPDATE Table1 SET Name = 'Calender' WHERE Name = 'Clalender'"
CurrentDb.Execute
errhandler:
Exit Sub
That's why I didn't notice it should have been
CurrentDb.Execute (SQL)
When the user started this command, Access said something like "Critical Error" and closed.
How come the error handling didn't catch that error? And why didn't Access tell me there was something missing when I wrote it? Usually it's quite pedantic about that.
The statement
CurrentDb.Execute
will not compile.
Compile error: Argument not optional.
Your victim ;) must have hit the error when they tried to run the code, which triggered an "on-the-fly" compilation. Error trapping in your code would not handle that because your code never got a chance to run (because it wouldn't compile).
In other words, Access would have gotten all pedantic on you if you had tried to run (or at least compile) your code.... :)
Try to compact and repair the database.
If that does not work, create a new empty database and import all the objects from the problematic database. Perhaps, you can import a few objects each time to determine which is the corrupted object (if any. Sometimes Access have this behavior and there isn't any bad object).

VBScript using stored procedures not working when introducing new column

I'm working on a desktop-application, database, webserver-access combination which someone wrote some years ago. My task is to do some optimications/refactoring and to introduce new features to this application(s). I have not much experience in developing web applications, so it's quite difficult for me to find a solution to my problem described below, hoping someone can help me.
The webapplication is written with ASP and VBScript having some small javascript functions which do not affect my question. It uses ADODB for communicating with the database.
The database is a MS-SQLserver 2008 database.
The desktop-application is written in C++/CLI using the .Net built-in features for communicating with the database. With this application everything is working.
For introducing some features I need to add new columns to tables in the database. Inserting and updating of the main table is done with stored procedures. I added a column named "internal" of type "bit":
ALTER TABLE maintable
ADD internal bit
GO
I altered the stored procedures for inserting and updating, just by adding the internal column and a parameter for it. I made only these changes:
1x line for the parameter
added internal in the column and values list for the insert
added setting internal column with parameter for the update
In the vbscript which already was working before any changes I added the code for appending the value for internal as new parameter (its the same for insert & update):
sqlcmd.Parameters.Append(sqlcmd.CreateParameter("#internal",11,1))
sqlcmd.Parameters("#internal")=0
After these changes the update und insert procedures of the vbscript stopped working. I tried several datatypes for the parameter and also changing the column (different name, different datatype). Nothing worked. The stored procedures themself are working fine when executed directly in the database and also when used by the desktop-application.
I started to debug everything with printing some debuginformations ect. I added try/catch in the stored procedures and a outparameter to get some errors according to this answer and I selected all input-parameters into a varchar outparameter. This caused the next strange results.
While updating "worked" (because the stored procedure didn't cause a database error and I got the input-parameter informations which didn't show wrong values, but no update was performed) inserting didn't workin any way. My tracing outputs where printed till the sqlcmd.Execute, this line seems to crash since the trace outputs after this line wheren't printed. As long as I did not use the outparameter the insert itself didn't work, but all trace outputs got printed. I tried to retrieve information about a possible database error directly after the execution of the code with:
DECLARE #ErrorVariable INT;
SET #ErrorVariable = ##ERROR;
SELECT #ErrorVariable AS ErrorID,
text
FROM sys.messages
WHERE message_id = #ErrorVariable;
GO
There was no database error.
Everything works fine from the desktop-application side. As mentioned the stored procedures executed directly in the database will work properly. I suppose the the error is somewhere in web-scripting-stuff. So now here are the concrete questions:
Why would the stored procedure not work (properly) when adding a new column to the database (it is there) and no syntax errors in the stored procedures or vbscript?
Why the sqlcmd.Execute stops working when adding a outparameter to the insert stored procedure? The try-block in the stored procedures includes everything between "AS BEGIN" and "END" having the catch-block directly before "END". Syntax is here also correct.
try to catch the error at the asp end.
On Error Resume Next
sqlcmd.Execute
for each objerr in yourconnection.Errors
Response.write objerr.Description & "<br/>"
next
On Error GoTo 0
Please check this link:
ADO Connection Object Errors Collection

SSIS Execute SQL Task SQL Command Issue

I have the following insert statement in my execute sql task in SSIS:
INSERT INTO dbo.SSISLogTest
(NodeID, BusinessDate, StartDate, StopDate, StepName, RecordCount, Message, Status, UserID)
VALUES (?,?,?,?,?,?,?,?,?)
When I run it within the task providing parameters it executes fine and inserts a record in the table.
When I run the package, this step fails with the following error:
"[Execute SQL Task] Error: Executing the query "INSERT INTO
dbo.SSISLogTest
..." failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with the
query, "ResultSet" property not set correctly, parameters not set
correctly, or connection not established correctly. "
Different connection providers require different syntax - all of the following must be set correctly:
The connection type (i.e. OLE DB, ADO...) Your choice, but aim to use the same throughout your application.
The number and specifics (Variable Name, Direction, Data Type, Parameter Name, Parameter Size) of parameters on the "Parameter Mapping" dialog.
The parameter syntax in the SQL query (i.e. your question marks.)
Please see an OLEDB example in the screenshots below and refer to Working with Parameters and Return Codes in the Execute SQL Task for details.