How to run multiple MySQL statements via JDBC sampler in JMeter - mysql

I am using JDBC sampler in JMeter 2.13.
I have around 100 delete statements in my JMeter sampler like below:
delete from abc where id >= ${Variable_Name};
delete from qwe where id >= ${Variable_Name};
delete from xyz where id >= ${Variable_Name};
Problem is that when I run a single statement in JDBC sampler, it works fine. But when ever I try to run 2 or more than 2 statements from my JDBC sampler. It always throws error.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delete from qwe where id >= 1;
Can someone please mention a workaround it? and how I can overcome this problem.

It seems you cannot execute multiple statements in a single JDBC Request element.
I had a similar situation where I needed to execute some clean up statements on the database before proceeding with the rest of the tests. I was able to achieve this by reading the SQL statements from an external file, using CSV Data Set Config nested in a Loop Controller, in a separate setUp Thread Group.
The elements were placed like this:
And I used the following configurations:
Loop Controller
Loop Count: Forever
CSV Data Set Config
Filename: /path/to/multiple-statements.sql
Variable Name: STMT
Recycle on EOF: False
Stop thread on EOF: True
JDBC Request
Query: ${STMT}
The Loop Controller is set to run forever, as the stop condition is set on the CSV Data Set Config. Each iteration will read one line of the file, set the variable STMT, then JDBC Request will execute the query ${STMT}.
When the end-of-file is reached, the setUp Thread Group will stop and the core test Thread Group will proceed.

Related

Sql Server sp_send_dbmail linked mysql server error

execute msdb.dbo.sp_send_dbmail
etc etc
#query = 'select * from Mysql...MemberRef4 as oi where oi.MemberId = 133363 '
The above is a query that I plugged into an existing working send mail method. MySql is a linked MySql database. I CAN run this query without any errors, correctly, by selecting the query code and F5. I am running this code and other MySql code joins with SqlServer and other linked servers - without any errors, including views/procs/etc.
However, the sp_send_dbmail method fails with :
Msg 22050, Level 16, State 1, Line 0
Failed to initialize sqlcmd library with error number -2147467259.
Note: this is the first time I'm trying to put MySql queries in sp_send_dbmail
Any help please. I really don't want stored procs that create temp tables/etc :(

SSIS Package Based on a avariable

Hi I've an SSIS Package which Does tasks like a)Truncate Last 7 days data from a table if any and then re-load it and all theses are placed in a sequence container and it run's fine.Now I'm planning to remove the hard coded value of 7 and introduce a variable NoOfDays which I can provide at run time.Can this be achieved?
I added a variable and tried to map it to the parameter of the ExecuteSQL Task...It gave the following error:
I even want the value to be available to the next step Data Flow Task
[Execute SQL Task] Error: Executing the query "delete from USER_CONTENT where CONVERT..." failed with the following error: "The variable name '#NoOfDays' has already been declared. Variable names must be unique within a query batch or stored procedure.
Statement(s) could not be prepared.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
The query I'm using is
delete from USER_CONTENT
where CONVERT(date,ISSUE_DATE)>=CONVERT(DATE,GETDATE()-7)
and it is against an OLE-DB connection.
I do not have enough points to post a comment so I will have to ask you this way: are you using query parameters with a "?", if not, then in order to use a package variable with a stored procedure, you will need to write your statement to use them, also, don't name your parameters, use the default 0,1,2 etc.. that the package assigns.

Programmatically setting a connection string for sql 2012 ssis packages

I am having an issue programmatically setting connection strings.
Here is an overview of my project. I am using 2012 SSIS and have two connections in my connection managers (Source and Destination and both are OLE DB connections). I have multiple packages I want to run. Each of these packages only contain Execute SQL tasks. Each task I have the SQL Statement connection type set to OLE DB, the connection is Destination, the SQL Source Type is a File Connection, and the File Connection is a file located on my C drive that is a script file that I generate in my program.
I have these packages deployed on my server which is a 2012 instance. The source and destination connections are also on my server but on a 2008 R2 instance.
I loop through N number of databases. In each loop I can set the Connection String and IntialCatalog properties by executing a SQL statement:
DECLARE #var sql_variant = N'Data Source=MyServerName\SQL2008R2;Initial Catalog=DatabaseName1;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;'
EXEC [SSISDB].[catalog].[set_object_parameter_value] #object_type=20, #parameter_name=N'CM.Destination.ConnectionString', #object_name=N'MAC', #folder_name=N'MAC', #project_name=N'MAC', #value_type=V, #parameter_value=#var
This does work since I can open up the configure option on my project and see that the connection string and initial catalog values change while I am stepping through the program. (I didn't include the SQL for the initial catalog but it is similar to the connection string)
Now when I execute this through my program, I the following errors:
The connection "{9C2C8088-CE67-4D93-81B8-EC364D6E78D1}" is not found. This error is thrown by Connections collection when the specified connection element is not found.
Is there a way to update the package so the Execute SQL Tasks have an updated connection?
As a side note, if I open the packages in Visual Studio and modify the connections, the packages execute. It is when I try to programmatically change the connections and execute or if I try to execute the packages that are deployed on the server when it errors.
I did see this question and although it is similar, I think it varies enough to have a separate question.
SSIS Connection not found in package. I have found a lot of great info here, just not what I am looking for yet.
Any help/advice is greatly appreciated!
Thanks
Mark
My suggestion would be to move your database looping and connection string setting inside your packages by taking advantage of SSIS's Foreach Loop container.
Create a new string variable in your package. Call it "User::DestinationConnectionString".
Right-click on your Destination connection and choose Properties.
Create an Expression for your connection's ConnectionString property and set to your User:DestinationConnectionString variable.
Put all of your connection strings in a table. Let's call it ConnectionStrings.
Create an Execute SQL task at the beginning of your package. Let's call it "Get Connection Strings."
Set the connection to where your ConnectionStrings table is.
Write a query to retrieve the connection strings.
Set the ResultSet to Full Result Set.
Set your Result Set to a variable of type Object. Let's call it User::ConnectionStrings. (The Result Name should be 0.)
Create a ForEach Loop Container. Name it "For Each Connection String."
Set the Collection Enumerator to Foreach ADO ENumerator.
Set the ADO Object Source variable to User::ConnectionStrings.
In the Variable Mappings tab, map Index 0 to your User::DestinationConnectionString variable.
Place your Execute SQL tasks inside your foreach loop.
Now when the package runs, it will loop through each connection string, assign it to the variable, which the connection uses to get its connection, which the SQL task then runs against.
If you don't know your database connection strings until runtime, you can just write them into the table then and then kick off your package.

SQL Task - Set Package variable

I have declared a variable at the package level compdate and am testing data flow to the variable by droping an Execute SQL Task in the Control Flow of the package.
In the task,
SQL Statement:
select ? = (getdate() - 1)
Parameter Mappings:
Variable Name: User::compdate
Direction: Output
Data Type: DATE
Parameter Name: 0
Parameter Size: -1.
Why am i getting error:
[Execute SQL Task] Error: Executing the query "declare #compdate date
set #compdate = (getdate() ..." failed with the following error: "Syntax error or access violation". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
I do not see why you need to execute an SQL statement to get the previous day as this can be done in various other ways.
To answer your question though, since you are trying to store the result of the SQL query from your Execute SQL Task you have to change the SQL statement that you have provided.
Your new query:
SELECT (GETDATE() - 1) AS DateVar
Where DateVar will be the single parameter that is returned which you need to map to your variable.
You need to delete your Parameter Mappings as they are not needed. Open up the Result Set tab and Add a new result. Set the Result Name to be DateVar and set the Variable Name to be your variable User::compdate
You then need to set up your Execute SQL Task to return a Single Row result set in the General tab, mapped to your variable. Select Single row for the ResultSet option.
Working with result sets is explained in great details here. Scroll down to the 'Working with a Single-Row Result Set' section, it has a great example which you can follow.
If you want to use without using the result set. try with following steps.
Create the stored procedure in your respective database. Following
code is an example.
CREATE proc GetYesterDay(#yesterday datetime output)
as
Select #yesterday=getdate()-1
Create the ADO.NET connection to run the stored procedure. In which, you can mention the direction of the input and output of the parameters.
Create the execute task and configure it as following screenshot.
Click on Parameter Mapping and configure as following screenshot.
Now SSISCompletedDate variable will be filled with respective data.
Hope this helps!

Storing values in variables using Execute SQL Task Object

I have an execute sql task defined in my package which will execute a stored procedure. When the stored procedure is executed it will return user credential. I have to store the credential in a variables and then use these credentials in a new script task.
The following is what I have tried so far.
STEP 1 - I have created SQL task
On General TAB set following properties:
Resultset: Single row
connectionType: OLE DB
Connection:SourceDestination
SQLSourceType:DirectInput
SQLStatement: Execute dbo.GetLoginInfo1
ByPassPrepare = False
STEP 2 - Parameter Mapping Tab
Variable Name = User::DatabaseUserName
Direction = Output
Data Type = NVarchar
Parameter Name = #UserId
Parameter Size = 50
STEP 3 - Result Set tab
Result Name = 0
Variable Name = User::DatabaseUserName
When I executed the task I got following errors.
[Execute SQL Task] Error: Executing the query "EXECUTE [dbo].[GetUserLoginInfo1]"
failed with the following error: "Value does not fall within the expected range."
Possible failure reasons: Problems with the query, "ResultSet" property not set
correctly, parameters not set correctly, or connection not established correctly
When I debug I got to see following information:
Break ON Pre execute:
User::DatabaseUserName = {Hi}
Break ON Post Execute: (error happens but the values gets chanage)
User::DatabaseUserName = {User1}
Sorry just forgot to mention the creation of variables. I have create one variable as listed below.
Name = DatabaseUserName
Scope = Package1
Datatype = String
Value = Hi
The below mentioned is the stored procedure that I have used.
ALTER PROCEDURE [dbo].[GetUserLoginInfo1]
AS
BEGIN
SELECT userid AS userid
FROM login_credentials
WHERE servername= 'server1'
END
I have tried and read lot many sites but I am still facing the problem.This is my second day on it and have to resolve it before tomorrow morning so any help will be really appreciated.
You should completely omit STEP2. (However, your procedure does not have any output column.)
STEP 1, and STEP 3 are all right. (In STEP 3 you could use userid in the Result Name column of the grid, but the ordinal will be absolutely good.)