Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSTEAD OF UPDATE Trigger not working

Status
Not open for further replies.

Bontebok

Programmer
Nov 18, 2002
63
US
I have created two views. The first view obtains records from Active Directory via an OPENQUERY() call.

Code:
CREATE     VIEW AD AS

SELECT     employeeid, sn, givenname, adspath, objectGUID
FROM         OPENQUERY(adsi, 
                      '<LDAP://OU=Corp Users,DC=Corp,DC=local>;(&(objectCategory=person)(sn=*));employeeid,sn,givenname,adspath,objectGUID;subtree') AD

The second view converts the results from the AD view into results to replace an existing real table. This is not the complete view, but you get the point.

Code:
CREATE       VIEW TIUSER AS

SELECT
	CAST(employeeID AS int) AS [USERID],
	CAST(displayname AS varchar(30)) AS [FULLNAME],
	[...]

FROM
	AD

WHERE
	employeeid IS NOT NULL


I found that the software attempts to UPDATE the view (appears as though it is clearing any locks) and this causes an exception because the column it is attempting to write to is a constant (returned by the view to make up for the table it is replacing).

To fix this problem, I thought a INSTEAD OF UPDATE trigger would correct it. I simply need to create the INSTEAD OF UPDATE trigger on the TIUSER view and this will allow me to 'fail gracefully' when the software executes the UPDATE statement.

This does not work for some reason and a new exception is thrown when the UPDATE statement executes. The exception is:

Code:
OLE/DB Provider 'ADSDSOObject' IUnknown::QueryInterface returned 0x80004002

My understanding is that the INSTEAD OF UPDATE trigger will fire instead of SQL Server attempting to update the data derived from the view. If this is true, what is SQL Server attempting to do to the AD view or to the OPENQUERY call? I also wrapped an INSTEAD OF UPDATE view around the AD view and I still get the same error.

When I profile the server, I do not see any further queries against the AD view or anything from the OPENQUERY call. I can't say that the trigger is not firing as the exception produced has now changed.

Any help would be appreciated.

Thanks,
Bontebok
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top