SSIS Exec T-Sql Statement Task connection string - sql-server

I dragged Execute t-sql statement task from toolbox. clicked new and created new connection.
when i executed, it executed successfully. there was no db showing in con string.
i changed the connection string to point to new server of above in Connection tab.
when i executed it, i recv errr
Description: Executing the query "DBCC SHRINKFILE (AppDB_log,300);" failed with the following error: "Could not locate file 'AppDB_log' for database 'master' in sys.database_files. The file either does not exist, or was dropped. ". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly. End Error
DBCC Shrinkdatabase command i am using.

Try running the query directly in SSMS in the database where you think it will be run based on your connection. If it fails then it's probably a problem with the query (i.e. the data file really doesn't exist). If it succeeds then it's probably a problem with your connection.
If it's a problem with the connection, try running profiler on your server and see what pops up when you run the SSIS package.

Copuld it be a permissions problem? Do you have the rights to run the command on that database?

Related

Failed to acquire connection. Connection may not be configured correctly or you may not have the right permissions on this connection

I am getting following error while attempting to execute the package. I can execute individual task successfully. But whenever attempt to execute whole package it gives me error.
SSIS Data flow on distributed transaction - [Execute SQL Task] Error: Failed to acquire connection "targetCon2". Connection may not be configured correctly or you may not have the right permissions on this connection.
I went through many links but nothing worked for me so starting a new thread. I checked SQL Agent Job - Connection may not be configured correctly or you may not have the right permissions on this connection?
SSIS package fail due to 'acquire connection' error
SSIS Package failing with "Failed to acquire connection" error
My distributed transaction service is running. DTC settings are correct. I am executing everything sequentially. Don't know whats wrong. I want to execute whole part in one transaction.
Please check the screenshots for more details.
I just experienced this issue as well. My problem was i had switched out the params file to point to a new environment. While the ADO connection 'test connection' button worked; when running the package it failed. I rebuilt the soution and it worked great after that.

issues in executing as400 command from SSIS execute sql task

I am working on an ssis package to process data from text file into as400 system. In one of the steps, i have to create a copy of an existing file object in iseries and i am executing the below command from execute sql task.
{CALL QSYS.QCMDEXC('CRTDUPOBJ OBJ(CKFMTWRK) FROMLIB(MYWRKLIB) OBJTYPE(*FILE) TOLIB(MYWRKLIB) NEWOBJ(CKFMTWRKPN) DATA(*NO)',0000000101.00000)}
This command works fine when i run it from the IBM Personal Communications terminal but throws below error when i do it from SSIS package.
[Execute SQL Task] Error: Executing the query "CALL QSYS.QCMDEXC('CRTDUPOBJ OBJ(CKFMTWRK) FROMLIB..." failed with the following error: "Routine *N in *N not found with specified parameters. SQLSTATE: 42884, SQLCODE: -440". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Further information on my environment:
I'm using sql server data tools 2015.
I've established the connection to as400 using Microsoft OLEDB provider for DB2.
I have sufficient permissions on the server (i guess, coz i am able to execute the commands from the terminal)
This is my first ever with as400 and I am stuck here in this step. I tried looking up online but there is nothing much that could help me in resolving this.
Any suggestions/help on this would be much appreciated.
Thanks.
Dvr
You are trying to perform AS/400 OS level command from a SQL environment (SSIS) which is not correct. QCMDEXEC is AS/400 command line interpreter while CRTDUPOBJ is creation of an identical object from the source with the option to duplicate its data as well.
Personal Communication terminal is fine cos you think you are using SQL service but actually not. It's AS400 command.
End up, you better do it over AS/400 terminal for duplicating object. Just use
CRTDUPOBJ OBJ(CKFMTWRK) FROMLIB(MYWRKLIB) OBJTYPE(*FILE) TOLIB(MYWRKLIB) NEWOBJ(CKFMTWRKPN) DATA(*NO)
The last keyword DATA(*NO) means create the object only but not the data, so you will get an empty file after completion.

Exception handling in SSIS Package Dynamic Connection

SSIS Scenario
I have a SQL variable of type object. It contains all the connection to different servers/databases. I want to connect to those databases one by one and run a query.
Expected Exception Handling
If the SSIS Connection manager(Dynamic connection manger) is unable to find the connection to the server (probably the server is down) I want to Skip that connection (Database/server) and log that into the table and move onto the next Connection (Database/Server). The SSIS package should not crash.
My Implementation
I have Successfully Configured the SSIS package to Use Connection Manager (Dynamic Connection Manager) and Foreach loop to loop through the SSIS variable of type object. but I am not able to skip the Connection if the server/database is not found. it generates error that the server/databsse not found / problem with the connection and the SSIS package fails.
my experience in SSIS is one week old
Any help will be appreciated.
How about setting --> Force execution Result property of the task to success
I was looking for the same fix too. Seems the normal OnError Eventhandling does not work for issues that arise when connecting to a source DB.
There is another workaround I wanted to mention. You can handle the error in the Data Flow Task (OnError Eventhandler, set the System-Variable "Propagate" in that Eventhandler to false). I think this is still required, but not sure. I use it also to log the exception.
Afterwards you can set MaximumErrorCount in ForEachLoop to "0" (which means unlimited). I'm not exactly sure why it works, but trying to find a way to handle the scenario you described, I found this.
==
Just as an interesting observation: For debugging purposes I added an OnError Eventhandler to the ForEachLoop and set a breakpoint there in a dummy script. It was never reached. Nonetheless the ForEachLoop failed all the time until I set MaximumErrorCount to 0.
I dont think its possible to continue the package execution once it encounters an error. You need to control this behavior through a SQL Server table (or any other table for that matter).
Once the package fails, you can set a flag in the table saying that the package failed. The next time the package runs, you can start from this point on and continue the execution. But automatically skipping the down server is kinda pulling a rabbit out of a hat.
Another way you can do this is to ping each server before hand in a separate package and store the ping results in a table. Only pick those records (servers) whose ping results were positive. Otherwise just skip the server.

Execute SQL Task error -

I get the following error when I call a stored proc within an execute sql task in SSIS.
"Description: Executing the query "Exec up_CallXXX" failed with the following error: "Incorrect syntax near '13'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly."
This is how it is set up:
ResulSet : None
ConnectionType : OLE DB
SQLSourceType : Direct input
SQL Statement : Exec up_CallXXX
IsQueryStoredProcedure : False
BypassPrepare : True
The stored proc runs fine when I execute it through SSMS.
Does anyone have an idea what is going on.
Thanks!
This isn't really a complete answer, but the quickest route to troubleshooting this problem is likely to be to capture the command that SSIS is actually trying to execute using a SQL profiler trace, since I think SSIS uses sp_executesql to carry out "Execute SQL" tasks.
Once you have the text of the query SSIS is running, you may find that you can replicate the error if you execute it in SSMS.
I've had this kind of problem when the session settings for my SSMS session are different from the session settings used by SSIS/SSRS. Given the error message, it might be worth checking the SET QUOTED IDENTIFIER values in both sessions - but this is a guess.

Drop all active database connections failed for Server when executing KillAllProcesses

I need to perform a database restore from my application. Before doing this, I want to kill all processes as follows:
private void KillAllProcessesOnSMARTDatabases(Server targetServer)
{
targetServer.KillAllProcesses(SMART_DB);
targetServer.KillAllProcesses(SMART_HISTORY_DB);
targetServer.KillAllProcesses(SMART_METADATA_DB);
SqlConnection.ClearAllPools();
}
However, when the first KillAllProcesses is run, I get the following exception:
Microsoft.SqlServer.Management.Smo.FailedOperationException: Drop all active database connections failed for Server 'MYServer'. ---> Microsoft.SqlServer.Management.Common.ExecutionFailureException: An exception occurred while executing a Transact-SQL statement or batch. ---> System.Data.SqlClient.SqlException: Only user processes can be killed.
The connection string used to create the server has sa credentials, however, the processes that need to be terminated are started under a different user. I tested the similar scenario and the test succeeded.
This started happening only recently. To me it appears there are some processes running that are not started by the user?
It would appear that your code is attempting to terminate all SQL Server Processes, which is not a good idea.
If you want to perform a database restore, you should set the database in question into either single_user mode or RESTRICTED_USER mode, the later being the most suitable.
Take a look at the following example of switching a database to RESTRICTED_USER mode and how to close any open user connections in the process.
How to: Set a Database to Single-User mode
You can use SMO to "kill" a particular database.
This will force a drop of all client connections to that database only and then drop the database itself.
Microsoft.SqlServer.Management.Smo.Server oServer = this.GetSmoServer();
oServer.KillDatabase(this.DatabaseName);

Resources