I have created two views. The first view obtains records from Active Directory via an OPENQUERY() call.
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.
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:
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
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