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] ?
Related
I was planning to use SSIS logging to get task level details (duration of running, error message thrown-if any, user who triggered the job ) for my package.
SSIS was creating dbo.syssisLog table under System table and it was working just fine. Suddenly it stops creating table under System table and start creating under Users table. Also now it is not logging some events which were logged previously when created under System table. Events like: PackageStart and User:PackageStart/User:PackageEnd event for some tasks.
Can anyone please guide me what's going wrong here ?
The table showing under System versus User tables is fairly meaningless but if you want the table to show the same, set it as a MS shipped table
EXECUTE sys.sp_MS_marksystemobject 'sysssislog'
The way database logging works in the package deployment model, is that SSIS will attempt to log to dbo.sysdtslog90/dbo.sysssislog (depending on your version) but if that table doesn't exist, it will create it for you. There is a copy of that table in the msdb catalog which is marked as a system object. When SSIS creates its own copy, it just has the DDL somewhere in the bowels of the code that does logging. You'll notice it also creates a stored procedure sp_ssis_addlogentry to assist in the logging.
As for your observation for inconsistent logging behaviour, all I can say is I've never seen that. The only reason it won't log an event is if the event doesn't occur - either a precursor condition didn't happen or the package errors out. If you can provide a reproducible scenario where it does and then doesn't log events, I'll be happy to tell you why it does/doesn't do it.
I have a Heterogeneous Link between Oracle 11.2.0.3 and SQL Server 2008. When I attempt to create views, or procedures that reference the Heterogeneous Services views for system tables, I get 4 errors listed below:
ORA-00604: error occured at recursive SQL level 1
ORA-02051: another session or branch in same transaction failed or finalized
ORA-06512: at "SYS.HS$_DDTF_SQLTABLES", line 58
ORA-06512: at line 1
As an example, these errors are created when I try to execute the following code:
CREATE VIEW ALLMYTABLES AS
SELECT * FROM ALL_TABLES#DBLINKNAME;
I am however able to create views on any normal table:
CREATE VIEW RANDOMTABLE AS
SELECT * FROM RANDOMTABLE#DBLINKNAME;
I have done some research to issues similar to this one, but have not found any references to this specific issue. I believe it may have something to do with the conflict between the concurrent operations of creating the view and the select * statement call to the SQL server database. Or perhaps that the records are not entirely fetched when the view is created.
I do not know the specifics of the HS link configuration and properties.
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.
I'm trying to understand how I can use an alias to reference another database in the same instance, without having to use a hardcoded name.
The scenario is as below:
I have a data db with stores data, an audit db which keeps all changes made. for various reason, i want to keep the audit data in a separate database, not least because it can get quite large and for reporting purposes.
In the data db, I don't want to reference this by a hardcoded name but an alias so that in different environments, I don't have to change the name and various sp's to reference the new name.
for example:
mydevdata
mydevaudit
If a sp exists in mydevdata such as which calls the mydevaudit, I don't want to change the sp when I go to test where the db's may be called mytestdata and mytestaudit. Again, for various reasons, the database names can change, more to do with spaces an instances etc.
So if I had procedure in mydevdata:
proc A
begin
insert into mydevaudit.table.abc(somecol)
select 1
end
when I go to test, I don't want to be change the procedure to reference another name, (assume for sake of argument that happened)
Instead I am looking to do something like:
proc A
begin
insert into AUDITEBALIAS.table.abc(somecol)
select 1
end
I am interested in finding out how I could do something like that, and the pro's and cons.
Also, dymnamic SQL is not an option.
thanks in advance for you help.
You may be able to use synonyms
CREATE SYNONYM WholeTableAliasWithDBetc FOR TheDB.dbo.TheTable
This means all object references in the local DB are local to that DB, except for synonyms that hide the other database from you.
You can also use stored procedures in the audit DB. There is a 3rd form of EXEC that is little used where you can parametrise the stored proc name
DECLARE #module_name_var varchar(100)
SET #module_name_var = 'mydevaudit.dbo.AuditProc'
-- SET #module_name_var = 'whatever.dbo.AuditProc'
EXEC #module_name_var #p1, #p2, ...
Obviously you can change module_name_var to use whatever DB you like
I've just posted this to How to create Sql Synonym or "Alias" for Database Name? which is a workaround for the same situation:
There is a way to simulate this using a linked server. This assumes you have two SQL servers with the same set of databases one for development/test and one live.
Open SQL Server Management Studio on your development/test server
Right click Server Objects > Linked Servers
Select New Linked Server...
Select the General page
Specify alias name in Linked server field - this would normally be the name of your live server
Select SQL Native Client as the provider
Enter sql_server for Product Name
In Data Source specify the name of the development server
Add Security and Server Options to taste
Click OK
The above is for SQL Server 2005 but should be similar for 2008
Once you've done that you can write SQL like this:
SELECT * FROM liveservername.databasename.dbo.tablename
Now when your scripts are run on the development server with the linked server back to itself they will work correctly pulling data from the development server and when the exact same scripts are run on the live server they will work normally.
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