Presql and postsql in Informatica is not getting executed - sql-server

PreSQL and postSQL in Informatica is not getting executed.
ISSUE DESCRIPTION :
I have table in Microsoft SQL server. I am trying to update/insert this table using Informatica powercenter session by calling SP through Stored Procedure Transformation. But its not happening. After further digging up, I got to know that reason behind this are triggers on table that we are trying to update/insert. There are couple of triggers defined on the table and it has got on insert and on update triggers also. So I thought of disabling all the triggers on the table in PreSQL and enable them back again in postSQL of the session that I am running. But its not working.
However when I execute the trigger disable statement directly on DB through Microsoft SQL server client and run the session, session is updating/inserting the records.
Below are the Presql and postSQL commands used by me:
BEGIN TRANSACTION
ALTER TABLE schemaname.tablename DISABLE TRIGGER ALL
commit;
BEGIN TRANSACTION
ALTER TABLE schemaname.tablename ENABLE TRIGGER ALL
commit;
Please let me know if I am going wrong anywhere/if there is any possible resolution for this.

your sql gets parsed by powercenter before going to the db.
Check the server config - there should be some option to send unparsed sql.

Related

SSDT/Visual Studio Database Project publishing DACPAC referenced DML table trigger SQL71501

I'm unable to publish SQL DML triggers inside of a VS Database/SSDT project. Everything else seems to publish updates/creations fine. However, my triggers aren't ever generated in the script. I can update/create stored procedures, table valued functions (TVFs), contracts, queues and services just fine using [dbo].[ElementName] references.
MSSQL Version: SQL Server 2014 RS2
i.e. these all work fine as their respective type (contract, service, stored procedure, etc.) and update/create based on the source/destination.
Contract:
CREATE CONTRACT [//Web/Queue/BasicContract]
(
[//Web/Queue/RequestMessage] SENT BY INITIATOR,
[//Web/Queue/ReplyMessage] SENT BY TARGET
)
Stored Procedure [$(SystemDb) is set as a SQLCMD variable]:
CREATE PROCEDURE [dbo].[z_Dist_Tans_Error]
AS
BEGIN
DECLARE #RecordCount INT
SELECT #RecordCount = COUNT(*) FROM [$(SystemDb)].dbo.bcerr
END;
However, I get a reference error with this trigger SQL code. Error is commented in-line:
CREATE TRIGGER [z_Trg_MatlAvailable_Delete]
ON [dbo].[Matlavailable] --SQL71501: Trigger: [dbo].[z_Trg_MatlAvailable_Delete] has an unresolved reference to object [dbo].[Matlavailable]
FOR DELETE
AS
BEGIN
END
I can add the SQLCMD variable into the trigger creation query. This fixes the compile errors. But, when publishing it doesn't seem to detect the trigger doesn't exist in the destination database so it's never created in the script.
CREATE TRIGGER [z_Trg_MatlAvailable_Delete]
ON [$(SystemDb)].[dbo].[Matlavailable] --Error Resolved but never published
FOR DELETE
AS
BEGIN
END
If I add the table's SQL definition inside of my project I can resolve those reference issues and it actually publishes the triggers. However, I'm attaching this DML trigger to our ERP system's database. I have no control over how that database's table will evolve over time and I don't want my projects "definition" of that table to override the existing one.
It seems like I can reference DACPAC tables fine in queries but not attaching triggers (and probably more). Is there some way to create triggers using [$(VariableName)].[Schema].[TableName] that publish with VS Database Projects or a way to reference DACPAC tables to create triggers using just [Schema].[TableName] ?

How to select recent errors that were raised in an SQL-Server database?

is there a way to do something like:
select top 100 * from sys.recent_raised_errors order by date
My scenario was that I had an application that executed a stored procedure in the database, and after installing a new trigger on a table, that procedure had an error raised inside of it, that caused the app to crash. It was obvious to me that the app is crashing due to a DB issue, but I had to debug the app or read its logs to find out what went wrong in the stored procedure.
try to do below step:
In Object Explorer, connect to an instance of the SQL Server and then expand that instance.
Find and expand the Management section
Right-click on SQL Server Logs, select View, and choose View SQL Server Log.
Or you can start profile to tracking the exception
I just did a testing with SQL Profiler
Create a tiger that will get a exception.
CREATE TRIGGER trig_test
ON dbo.T
AFTER INSERT,DELETE,UPDATE
AS
BEGIN
SET NOCOUNT ON;
SELECT 1/0
END
GO
INSERT INTO dbo.T( remark )VALUES ( '')
The following is the message that got from Profiler.

Retrieving single row within transaction hangs

I run several SQLs ( select, update and insert ) within single database connection and transaction, one of the SQLs is to retrieve the balance of an account
select top 1 balance from sample_table where account_id={accountId} order by id desc
This SQL hangs only and only if there are no records actually in the table "sample_table" for the account {accountId} , otherwise it works normally.
Hangs means it waits until a timeout exception error occurs, and during this 'wait' , executing the SQL from Sql Server management studio also hangs.
I'm using Sql Server 2008
thanks
ِEDIT:
After multiple attempts to perform same action, it does work and all the records are inserted properly and then the app works like the charm after that.
Restore the database, then the issue is back again.
The issue is fixed after rebuilding the table, basically executing this SQL:
alter table sample_table rebuild

Why are the database rows are getting deleted automatically sql 2008

Everyday, some of my database rows are getting deleted automatically.
Even the log files are getting deleted, so I am unable to check who deleted those files.
I dont understand what to do.
If the SQL server is pre-production, you could just yank all delete rights to the target table and wait to see who complains. If deletes are not allowed on this table anyway, even in production, then it would be a good idea to restrict that functionaity moving forward.
Beyond that, try adding a delete trigger to the table to do auditing. You can get the source IP address, logged in user info, etc. You can even rollback the delete if needed.
Here's a good article on using triggers for auditing.
http://weblogs.asp.net/jgalloway/archive/2008/01/27/adding-simple-trigger-based-auditing-to-your-sql-server-database.aspx
Edit:
If you want to stop all deletes on a table, you can use the following trigger.
CREATE TRIGGER dbo.MyTable_Delete_Instead_Of_Trigger
ON dbo.MyTable
INSTEAD OF DELETE
AS
BEGIN
raiserror('Deletes are not allowed.', 16, 1)
END
Run SQL Profiler against the DB capturing all RPC Completed and SQL BatchCompleted events and review it to find whatever is performing the deletes.

SQL Server 2008: MERGE command on a table that has a trigger causes an error

I have a stored procedure that uses the MERGE command to synchronize dbo.tableA with [mylinkedserver].dbo.TableA.
TableA has an insert/update trigger associated with it. To keep things really simple all the trigger does is
print 'I am a simple trigger because i dont want to cause errors'
When the SP is executed (thru a .net windows application), it throws this error:
OLE DB provider "SQLNCLI10" for linked server "MyLinkedServer"
returned message "No transaction is
active."
If I delete the trigger and execute the stored proc again, it executes absolutely fine.
The stored procedure also runs fine (with the trigger) if i run it through SSMS.
MSDTC is enabled on both servers.
Server is Windows 2008 server, SQL Server 2008 with service pack 2.
Why would a trigger cause this error ?!?!??
Trigger implementation with Merge is a little tricky. It boils down to "for each action specified in the merge statement there must be a trigger".
TechNet Says "If the target table has an enabled INSTEAD OF trigger defined on it for an insert, update, or delete action performed by a MERGE statement, then it must have an enabled INSTEAD OF trigger for all of the actions specified in the MERGE statement."
http://technet.microsoft.com/en-us/library/bb510625.aspx

Resources