SQL 2012 :: Executing SP From Trigger?

Mar 21, 2014

Below is my requirement..

Create trigger on Table_XYZ ( After Insert,After Update)
select @var=Col_Last field is null from inserted
if @var is null
Execute sProc1
create proc sproc1
Business logic will create two csv files. Success and error files
success record will be deleted from Table_XYZ,
Error records updated with error_message.

Problem:- When i am updating Col_Last value to null or insert a record with NULL for Col_Last

Trigger is firing and executing SP.....But i was not able query the Table_XYZ and taking too much time...

sp_who2 shows blocked by...my SPID only

when i am executing SP alone ...every thing works fine....

when i am doing testing on trigger with Insert/Update... i am getting executinf query... no response...

If i comment below ones in Trigger...working fine...

--if @var is null
--Execute sProc1

View 1 Replies


ADVERTISEMENT

Executing DDL In A Trigger

Nov 15, 2000

Dear All,
I would like to execute a DDL statement(create table) in a trigger. The DDL statement is stored as a field in another table. I have read that sql statement into a variable of type varchar. How do I execute that sql statement.
Thanks in advance

View 3 Replies View Related

Executing Trigger

Nov 28, 2007



Hi Everybody,


I am new to ms sql server i had small proublem

i am created Trigger it will work so fine command successfully

how can i executed that Trigger plz help

Regards
subu

View 4 Replies View Related

Trigger Not Executing

Aug 13, 2006

I will try to keep this as simple as possible and make a long story short. The college I work for has bought a third party package to basically run the operations of the school. There is a component for registration, admissions, billing, etc. It also has a web component so students can access their school information from anywhere. The backend for all of this is SQL Server. To make things easy, the vendor has provided us with the steps to bulk load users, via DTS, into the system and create their accounts for the web portion. The way this works is as follows:

I create a CSV file which I then load via DTS into their "Bulk Load" table. This table has an "on insert" trigger that fires off when the load happens on the "Bulk Load" table. The trigger verifies that the user exists in the system, encrypts the password I provide in the file and inserts the record into an "Accounts" table. This "Accounts" table is where the system checks when a user logs in. Everything works fine on our test server, but in live, the trigger does not execute. The DTS package executes and the "Bulk Load" table gets updated, but the "Accounts" table does not. My file has 382 valid students and again, it worked fine on the test server.

Differences between the servers:

1. The DTS packages are the same, except for the server they connect to.

2. The test server is stand alone, while the production server is clustered.

What I tried:

1. A ran the alter statement to enable the trigger thinking it might be disabled.

2. Dropped the trigger on production and re-created it with the trigger from our test server.

3. Tried to run a trace (I had never done that before). Noticed some sp's running, but none of them were sp's found in the trigger.



Any thoughts or ideas as to what I can check? Do triggers have certain permissions and if so, where can I make sure I have the permissions. I should have full access under my account as should the account that SQL Server Agent is logged in as.

Thanks for any help.

Pete

View 17 Replies View Related

Sql Command Executing Trigger

Jan 5, 2004

hi.
I must get i trigger the sql command, which execute trigger.

View 5 Replies View Related

Executing A Views From A Trigger

Mar 1, 2006

Hi,I am new to using SQL. I want to be able to exucute a query that Iplace in a view. I want this views to be executed every time a valuechange in one of the table in a particular field. So my guess was touse a trigger that will call the views every time the data change inthe selected table. Is this the proper way of doing thing? Should Iuse other SQL tools to achive this. I search for exemple of triggerexecuting views but did not found anything as of yet. Let's use thisdummy name for the exemple:Database: DB1Table: Tbl1Special field in Tbl1: flagViews name: views_01Thank you.Philippe

View 7 Replies View Related

Trigger Not Executing CLR Code/stored Proc

May 7, 2008

I have a database trigger that is set to call a CLR trigger/stored proc when a certain field in a table is updated. The issue is that if i execute the stored proc manually in enterprise studio, it works perfectly but the same call made through the trigger does not go through. A few more details -


I have CLR integration enabled on the sql server.

The dbo has UNSAFE ASSEMBLY rights

I have the both the assembly and the serialized dll imported in the database.


Here's the definition of the stored proc -


CREATE PROCEDURE [dbo].[WriteXMLNotification]

@TaskID [nvarchar](20)

WITH EXECUTE AS CALLER

AS

EXTERNAL NAME [DataInterfaceWebServices].[TaskUpdateXMLWriter.WriteXMLNotification].[run]



and the trigger -



CREATE TRIGGER [dbo].[tr_Task_U]

ON [dbo].[_Task]

FOR UPDATE, INSERT AS

IF UPDATE (TaskType_Status) OR UPDATE (TaskType) OR UPDATE (TaskType_SubType1)

BEGIN

SET NOCOUNT ON;

DECLARE @status AS INT

DECLARE @taskType AS INT

DECLARE @taskSubType AS INT

DECLARE @taskID as sysname

DECLARE @cmd as sysname

DECLARE @parentTask as sysname

DECLARE @NotificationXMLTaskID as sysname



SELECT @status = [TaskType_Status] FROM inserted

SELECT @taskType = [TaskType] FROM inserted

SELECT @taskSubType = [TaskType_SubType1] FROM inserted

SELECT @taskID = [TaskID] FROM inserted

SELECT @parentTask = [Parent_TaskID] FROM inserted

SELECT @NotificationXMLTaskID = [MCCTaskID] FROM _TaskNotificationXML WHERE [MCCTaskID] = @parentTask



IF (@status = 2602) AND (@taskType = 2282) AND (@taskSubType = 19500)

BEGIN

exec WriteXMLNotification @taskID;

END

ELSE IF (@taskType = 2285) AND (@parentTask IS NOT NULL) AND (@NotificationXMLTaskID IS NOT NULL)

BEGIN

exec WriteXMLNotification @parentTask;

END



END


I stepped into the trigger and it seems to execute the line " exec WriteXMLNotification @taskID;" but nothing happens, but if I run that same line manually, it works. Could it be that the impersonation by the EXECUTE AS clause is causing it to fail?

Please advise!

Thanks in Advance,
-Mihir Sonalkar.

View 1 Replies View Related

Executing Store Procedre By Calling It From An Insert Trigger?

Feb 10, 2000

hi, I have a trigger on a table for insert, once there is new data into that table I want to run a nother store procedure by passing all input from inserted to the store procedure as input parameter. can I do that.

Thanks

Ali

View 4 Replies View Related

Trigger Executing Linked Server Stored Procedure

Jul 3, 2006

What is the syntax for creating a update trigger and passing the values which were updated to a stored procedure on a linked server?? Specifically need syntax for updated value, as well as the syntax for executing the stored proc on the linked server.

Thank you

View 1 Replies View Related

Transact SQL :: Executing Stored Procedure Within Trigger Failing But Separate Works

Nov 4, 2015

I have stored procedure on Server A which goes to ServerB to check and update table and then update on Server A as well.I have Trigger which suppose to execute stored procedure (as i mentioned above). But it failed with this error:--

Trigger code:--
CREATE TRIGGER [tr_DBA_create_database_notification] ON ALL SERVER 
AFTER CREATE_DATABASE
AS 
--execute dbadmin.dbo.usp_DBA_Refresh_DBAdmin_Tables

Error:--The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "xxx" was unable to begin a distributed transaction.Process ID 62 attempted to unlock a resource it does not own: DATABASE 21. Retry the transaction, because this error may be caused by a timing condition. If the problem persists, contact the database administrator.

Same stored procedure, if i execute manually or if i create sql job and execute this stored procedure, it works just fine..In trigger also, if i execute start job which has stored procedure, it works.My question is,why it failed when i execute stored procedure in TRIGGER.

View 5 Replies View Related

SQL Server Admin 2014 :: Logon Trigger Executing Multiple Times For Single Connection?

Jan 30, 2015

I am trying to create a logon trigger. As I am testing this, I discovered that each time I do a connection, I get 19 rows, inserted into my audit table. I ran profiler, and I see it is going through the logon trigger multiple times, for a single connection. So, what am I doing wrong? The code is fairly simplistic, and the profiler doesn't give a clue, as to what is going on. When I look at the output, I see the spid for the first couple of connections are different, then a spid, that is different from those 2 is in the next 17 rows. But, when I do an sp_who2, that spid does not exist.

This issue was noticed on a 2012 version, that I was first testing on, then had the same issue on a 2008 R2. I am currently testing on a 2014 version, that is doing the same thing. Is the logon trigger itself, firing, and causing this?

I also tried using the After Logon option, and got the same issue.

Here is the code:

CREATE TRIGGER LogonAuditTrigger
ON ALL SERVER WITH EXECUTE AS 'sa'
FOR LOGON
AS
BEGIN
DECLARE @Body NVARCHAR(2000),

[code]....

View 0 Replies View Related

SQL 2012 :: Executing Stored Procedure As Different User

Nov 26, 2014

I have a database user dsrpReader that can execute stored procedures in one database; it's the only thing that this user can do. Works great except for the below stored procedure.

[code=sql]
CREATE PROCEDURE [dbo].[__usp_DatabaseFieldsize_Get]
@pTablename nvarchar(128)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from

[Code] ....

If I run the above as an administrative user (windows login), I get N rows of information back (N > 0). If I run it as an unprivileged user (see beginning of post), I get 0 rows back and no error messages.

Adding 'with execute as owner' solves the issue, but I'm not sure of the implications. Am I opening up the database to attacks (or even the complete server)?

If so, how to continue.

In an attempt to solve the issue I have given permissions to the user dsrpReader on the information_schema.columns but have no success. It did not work. This was just a try, I actually want to set up a dedicated user with some permissions that I can use in the 'with execute as 'limiteduser'.

View 2 Replies View Related

SQL 2012 :: Executing Parameterized Stored Procedure From Excel

Aug 12, 2013

I'm using Excel 2010 (if it matters), and I can execute a stored procedure fine - as long as it has no parameters.

Create a new connection to SQL Server, then in the Connection Properties dialog, specify

Command Type: SQL
Command Text: "SCRIDB"."dbo"."uspDeliveryInfo"

but if I want to pass a parameter, I would normally do something like

SCRIDB.dbo.uspDeliveryInfo @StartDate = '1/1/2010', @EndDate = GETDATE()

but in this case, I would want to pass the values from a couple of cells in the worksheet. Do I have to use ADO (so this isn't a SQL Server question at all?)

View 9 Replies View Related

Order Of Executing Rebuild / CheckDB After Upgrade To 2012

Aug 28, 2015

what is the order of executing rebuild/checkdb after attaching database in SQL 2012 from 2008R2.

1. change compatibility mode
2. run dbcc checkdb
3. alter index rebuild all on <table> with fillfactor=90

Is above order ok? or there is no particular order to execute above 3 steps after upgrade.

View 6 Replies View Related

SQL Server 2012 :: Case Statement Executing A Stored Procedure

Aug 20, 2014

Is this possible, I am trying to execute a stored procedure depending on what parameter is selected, something like this????

Case
when field = 'value' then execute sp_procedure else execute sp_procedure_2 end
case

View 1 Replies View Related

SQL Server 2012 :: Permissions For Executing Procedure Which Executes Other Procedures?

May 13, 2015

I have a stored procedure which executes about forty other stored procedures in several different databases. All of these other procedures truncate tables and insert new data into those tables selected from still other tables.

I want to run this top-level procedure using an account which can't do anything else.

Is there a simple way to give it all the permissions it needs without empowering it to do anything else?

View 0 Replies View Related

SQL 2012 :: Parameter Error When Executing A Package With Built In Stored Procedures

Jul 23, 2014

I am using Excel VBA to run a stored procedure which executes a package using the built-in SQL Server stored procedures. The VBA passes two values from excel to the stored proc., which is then supposed to pass these "parameters" to the package to use as a variable within the package.

@Cycle sql_variant = 2
WITH EXECUTE AS 'USER_ACCOUNT' - account that signs on using windows authentication
AS
BEGIN
SET NOCOUNT ON;
declare @execution_id bigint

[code]....

When I try to execute the package, from SQL Server or Excel using the Macro I built, I get the following error:"The parameter '[User::Cycle]' does not exist or you do not have sufficient permissions." I have given the USER_ACCOUNT that runs executes the stored procedure permission to read/write to the database and the SSIS project folder.

View 4 Replies View Related

SQL 2012 :: Error Executing DTSX From SSISDB But Runs Fine When Run It Manually

Sep 12, 2014

When i run it from sql server data tools on the test box it runs fine. However when i run it from the ssisdb directly i get the below error.

reload table tablename1 from Excel file:Error: The "filetoload.Outputs[Excel Source Output].Columns[Product]" failed because truncation occurred, and the truncation row disposition on "filetoload.Outputs[Excel Source Output].Columns[Product]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.

reload table t from Excel file:Error: There was an error with filetoload.Outputs[Excel Source Output].Columns[Product] on filetoload.Outputs[Excel Source Output]. The column status returned was: "Text was truncated or one or more characters had no match in the target code page.".

View 1 Replies View Related

SQL 2012 :: Error Executing Packages In SSIS Project On Server After Editing On Client

Sep 24, 2014

I am building a bunch of packages on our new server and all was going well until I edited the project using the client tools on my PC. I now receive the below error if I try to execute any of the packages on the server (all is still fine on the client). I have scoured the net but I don't seem to be able to come up with a solution. I have tried altering the folder & object permissions for my login (that created the project on the server and edited using the client) but I still get the error.

ERROR:

TITLE: Microsoft Visual Studio
------------------------------
Failed to start project
------------------------------

ADDITIONAL INFORMATION:

Exception deserializing the package "Access to the path 'G:VisualStudioTestTestbinDevelopmentTest.ispac' is denied.". (Microsoft.DataTransformationServices.VsIntegration)

------------------------------
Access to the path 'G:VisualStudioTestTestbinDevelopmentTest.ispac' is denied. (mscorlib)
------------------------------
BUTTONS:

OK
------------------------------

View 4 Replies View Related

Stored Procedure Executing Durations Are Different Between Executing From Application(web) And SQl Server Management Studio - Qu

Jan 24, 2008



Hi,

I have a web application using Stored Procedure (SP). I see that there's a SP taking long time to execute. I try to capture it by Profiler Tool, and find out that with the same SP on the same db with the same parameter. The duration of executing by my web app is far bigger than the duration of executing on SQl server management studio - query window

Please see the image through this url http://kyxao.net/127/ExecutionProblem.png


Any ideas for this issue?

Thanks a lot

View 1 Replies View Related

Stored Procedure Executing Durations Are Different Between Executing From Application(web) And SQl Server Management Studio - Query Window

Jan 23, 2008

Hi,I have a web application using Stored Procedure (SP). I see that there's a SP taking long time to execute. I try to capture it by Profiler Tool, and find out that with the same SP on the same db with the same parameter. The duration of executing by my web app is far bigger than the duration of executing on SQl server management studio - query windowPlease see the image attached http://kyxao.net/127/ExecutionProblem.png Any ideas for this issue?Thanks a lot Jalijack 

View 2 Replies View Related

Different Results When Executing From .NET Component Compare To Executing From SQL Management Studio

Oct 10, 2006

Hi all,I am facing an unusual issue here. I have a stored procedure, that return different set of result when I execute it from .NET component compare to when I execute it from SQL Management Studio. But as soon as I recompile the stored procedure, both will return the same results.This started to really annoying me, any thoughts or solution? Thanks very much guys

View 2 Replies View Related

SQL 2012 :: How To Capture Data Flow Component Name Dynamically While Package SSIS Package Is Executing

Jun 3, 2014

I would like to fetch the data flow component name while package is executing. Since system variable named [System::SourceName] only fetches name of the control flow tasks? Is there a way to capture them?

View 5 Replies View Related

SQL 2012 :: Create Trigger Syntax

May 30, 2014

ALTER TRIGGER [dbo].[Trigger1]
ON [dbo].[Table1] with execute as SELF
AFTER INSERT

[code]....

I am trying to create a trigger so every time a entry is made on a table, and the Colum1 is 'entry', it starts a job. But the users running the inserts do not have permission to Start jobs so I need to make it run as a super user. Where do i put the syntax in here? I Have tried Execute as login 'superuser' before the exec statement but it errors on the principal not being valid

View 1 Replies View Related

SQL 2012 :: Trigger Not Inserting Any Values?

Aug 11, 2014

I have a trigger that searches for duplicates before inserting values.

I have written the trigger however its not inputting values into the column at all.

see my trigger:

ALTER TRIGGER DUPLICATES
ONAMGR_User_Fields_Tbl
AFTERINSERT,
UPDATE
AS
Declare @AlphanumericCol varchar (750)
Declare @Counter integer

[code]....

View 5 Replies View Related

SQL 2012 :: Trigger Or Agent Job To Run SP Constantly?

Aug 22, 2014

I have a database with a table called RAW, this table receives msgs via XML, sms and various other formats. The data is written into this table at a rate of approximately 50-100 rows per minute.

I have a SP which takes the data written into the raw table and performs various actions looks for account information, writes to a log table, writes to incident table’s gets GPS information and so on.

The records written into the raw table need to be processed at almost instantly with a maximum of under a minute from when they arrive into the table.

At present there is a sql agent job which executes the SP, this consist of a step to execute the SP which on completion moves to the next step which is a loop waitfor delay and then back to step 1.

The trouble is it never actually finishes and runs 24/7 there is no break point for error handling and occasionally the records that arrive in the raw table do not get processed and the job has to be restarted for it to pick them up again.

I am looking for best way to handle this process, I thought about a trigger but the performance impact on using a trigger was too heavy to consider.

View 2 Replies View Related

SQL Server 2012 :: How To Create A DML Trigger

Jan 6, 2015

THe Scenario is We have Tables like parent and Child Table.

Like we have Child Table as Name AcademyContacts,In that we have Columns like

Guid(PK)Not Null,

AcademyId(FK), Not Null,

Name,Null

WorkPhone,Null

CellPhone,Null

Email Id,Null

Other.Null

Since we have given Null to ''Workphone'',''Cellphone '', ''Email ID''.when inserting the data into these table if the particular columns are empty while inserting also the data will get populate into the table.And I need is if these columns are ''Workphone'',''Cellphone'' , ''Email ID'' they cant insert the data into table.Like it must trigger like ''Please enter atleast one of these ''Workphone'',''Cellphone'' , ''Email ID'' columns.

View 5 Replies View Related

SQL 2012 :: Disable And Enable Trigger?

May 25, 2015

I have a trigger that I disable so I can do some operations on a table.

After the operations are completed I do the enable using the enable trigger comand.

Do I need to do something else to put back the trigger working as it was before the disable comand?

View 3 Replies View Related

SQL 2012 :: Delete Trigger On One Table

Jun 8, 2015

I have a delete trigger on one table. When I delete a single row in this table that deleted record will be recorded to a history table.But sometimes my delete will delete more than one record. In this case also only one record is being recorded into the history table.How can I record all the deleted records into the history table when multiple records are deleted with one single delete statement?

View 4 Replies View Related

SQL Server 2012 :: Disable Only One Trigger Action?

May 6, 2014

I have a trigger that executes AFTER INSERT, UPDATE, DELETE. Is there a way to disable and then reenable only the "AFTER DELETE", letting AFTER INSERT, UPDATE act normally?

View 6 Replies View Related

SQL Server 2012 :: UPDATE Trigger Failing

Jan 30, 2015

We have an UPDATE trigger that is failing. This seems like a basic task - we want to write a record to a separate tracking table when our main transaction table is updated for any reason. Our assumption is that we have a reference to the data from the "inserted" record that was just updated. The scenario here is that we are running a batch process which READS several thousand records in our transaction table each evening.

We then mark each individual record as processed on the transaction table and expect that the UPDATE trigger will successfully fire (it is not). The version of our trigger listed below shows our attempt to deal with the fact that TransactionID does NOT exist from "inserted." We also have a version of this trigger that deals with INSERTS - it works flawlessly.

ON [dbo].[FPS_Transaction]
AFTER UPDATE
AS declare @trxId uniqueidentifier;
BEGIN TRY
SET NOCOUNT ON

[code]...

View 6 Replies View Related

SQL Server 2012 :: Concurrent Connection Trigger

Jun 16, 2015

I am STIGing a database and have to create a trigger that will stop any connection from occurring after a certain limit has been reached. For example I set the concurrent connection to 50 so I need a trigger that will stop any connection from all logins happening after 50.

The STIG info:
Rule Title: SQL Server must limit the number of concurrent sessions for each system account to an organization-defined number of sessions.

STIG ID: SQL2-00-000100

The below triggers works, but for only the one login, so how can I have it include all logins for that SQL instance.

CREATE TRIGGER connection_limit_trigger
ON ALL SERVER WITH EXECUTE AS 'login_test'
FOR LOGON
AS
BEGIN
IF ORIGINAL_LOGIN()= 'login_test' AND
(SELECT COUNT(*) FROM sys.dm_exec_sessions
WHERE is_user_process = 1 AND
original_login_name = 'login_test') > 3
ROLLBACK;
END;

View 2 Replies View Related

SQL 2012 :: Using Linked-server During (logon Trigger)

Oct 8, 2015

Used linked-server during logon trigger? is it possible? i know we can access tables, SPs, etc with in that server, if i want to check something in other server during logon trigger, can i do it?

View 0 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved