• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Trigger Does Not Fire on View When Updated Through ADO

[I have also posted this question in the SQL section and will award points on either or both for a good solution]

The trigger in question works perfectly in Query Analyzer, but when I call it from my ASP page through ADO (code below) the trigger isn't being fired.  I get the error:
Microsoft OLE DB Provider for SQL Server error '80004005' Cannot insert or update columns from multiple tables.

For clarity -  tblAuthor is a view which I'm trying to use to replace the real tblAuthor (renamed to tblAuthor_Org)

The code on the ASP page is striaght forward:
Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsCommon = Server.CreateObject("ADODB.Recordset")
adoCon.connectionstring = strCon
adoCon.Open
strSQL = "SELECT * FROM tblAuthor where Author_ID= 5"
rsCommon.CursorType = 2
rsCommon.LockType = 3
rsCommon.Open strSQL, adoCon
With rsCommon
        strRealName = "Christy M"
        .Fields("Real_name") = strRealName
        strHomepage="www.url.com"
        .Fields("Homepage") = strHomepage
        .Update
End With

I really don't want to have to change the way the query is being called with ADO.  I'm trying to implement the joining of two databases of information by using a view to grab pieces for each.  If I can replace the table tblAuthor with a view called tblAuthor I'd be set but first I need to be able to update the view (ie- use a trigger).

View:
CREATE VIEW dbo.tblAuthor
WITH  VIEW_METADATA
AS
SELECT     auth.Author_ID, auth.Group_ID, auth.Username, auth.Real_name, auth.User_code, cia.Password, auth.Salt, email.Email AS Author_Email,
                      cia.WWW AS Homepage, auth.PM_notify, cia.CIAID
FROM         DB1.dbo.tblAuthor_Org auth INNER JOIN
                      DB2.dbo.Email email ON email.Email = auth.Author_email INNER JOIN
                      DB2.dbo.CIA cia ON email.CIAID = cia.CIAID

The simple trigger I'm using to test:
CREATE TRIGGER dbo.TestUpdateTrigger ON [dbo].[tblAuthor]
INSTEAD OF Update
AS
Update tblAuthor_Org SET Real_name=(SELECT CIAID FROM inserted) WHERE Author_ID=(SELECT Author_ID FROM inserted)

The trigger will actually be changed to DO something if I can get this to work.  As it is it would simply prove that data from the second database was being moved into the first

I found a knowledge base article on Microsofts site that I thought for sure would fix the problem http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q304096 Unfortunately it still didn't work after adding WITH  VIEW_METADATA (the MS suggested fix) to the Create View statement.

Thanks in advance for the help.  Please let me know if any additional details are required.
0
CMcLennan
Asked:
CMcLennan
  • 6
  • 4
  • 3
1 Solution
 
fritz_the_blankCommented:
My understanding is that you cannot update a recordset that has multiple tables--you must update each table separately.

FtB
0
 
CMcLennanAuthor Commented:
I certainly hope that's not the case :/

The microsoft knowledge base article I linked certainly seems to indicate it's possible.
0
 
fritz_the_blankCommented:
Right--but notice how they update each table individually through a separate literal sql insert. You are attempting to update a recordset that may comprise multiple tables.

FtB
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
CMcLennanAuthor Commented:
Don't mean to be a pain but those separate literal sql insert statements are just populating the test data in the tables.

I don't think you're understanding the code on the knowledge base article.
0
 
fritz_the_blankCommented:
Sorry, I misread this. The first part of your code is fine--it updates a single table through the recordset, so that should be fine.

Let me take a quick look at the second part. My next thought is that this may be permissions based--'80004005' is often a permissions related error, and if your trigger works fine when called through a server-side event, it seems to function fine. I wonder if the IUSR_ account needs to have permissions within SQL Server in order for this to work?

FtB
0
 
CMcLennanAuthor Commented:
Thanks FtB.  I don't believe this is a permission error.  When I change to code to connect to tblAuthor_Org directly it works fine.  This seems very much caused by the trigger not firing.
0
 
fritz_the_blankCommented:
I am sorry, I was thinking about whether the IUSR account needed permissions in order for the trigger to fire.

FtB
0
 
fritz_the_blankCommented:
In any event, if this does not work on the server, then permissions are not the issue. I really hope that one of the folks in the SQL Server TA can set this straight for you.

FtB
0
 
Anthony PerkinsCommented:
See my comment in your cross posted question:
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_21126652.html

As a cautionary note, EE frowns upon more than 500 points offered per question.
0
 
Anthony PerkinsCommented:
Fritz,

Actually it looks like if anything the othere thread needs to be deleted.   You were right in your original assessment. See my comments from the other thread:

<quote>
Actually I may have totally misunderstood the question. The problem is that you are attempting to update a view made up of more than one table and is unrelated to the trigger.  I suspect the error is ocurring in the Update method and is not going beyod that to the Trigger.  
Simply put, in general you cannot do an update when more than one table is involved.  See here for more info:
PRB: ASP Error "The Query Is Not Updateable" When You Update Table Record
http://support.microsoft.com/default.aspx?scid=kb;en-us;174640
</quote>
0
 
CMcLennanAuthor Commented:
Hi all,

Sorry didn't mean to over-spend with my cross post. I just really needed a solution.  

I guess although I can get the trigger to work on the server and update both tables through the view, I can't do the same thing from ADO with the same call.

If 'it can't be done' is the answer that's still an answer isn't it.

How would you recommend I handle the points?

Thanks,

Christy
0
 
fritz_the_blankCommented:
You may request a refund and delete in the Community Support area or you may accept the comments that helped you the most as an answer. If more than one person was helpful in a thread, please use the split button to distribute points to reflect how you feel you were helped by each contributor.

FtB
0
 
Anthony PerkinsCommented:
Once again the problem is not in the Trigger, but rather in the fact that you are attempting to update a View made up of more than table.  If the columns to be updated belong to more than one table, it cannot be done. EOS
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now