FIX: You may receive the "Cannot insert or update columns from multiple tables" error message when you try to insert or to update data in a multi-table view by using a server-side cursor (835677)



The information in this article applies to:

  • Microsoft Data Access Components 2.8

SYMPTOMS

When you use a server-side cursor from a client application, and you try to insert or to update data in an updatable SQL Server view that is based on multiple SQL Server tables, you notice that the INSTEAD OF trigger that is defined on the view does not fire. Additionally, you notice that the data is not updated in the view, and you may receive an error message that is similar to the following:
Run-time error '-2147467259 (80004005)':

Cannot insert or update columns from multiple tables.
This problem occurs if you use Microsoft OLE DB Provider for SQL Server from the client application to connect to the instance of Microsoft SQL Server that contains the view.

RESOLUTION

Service pack information

To resolve this problem, obtain the latest service pack for Microsoft Data Access Components 2.8. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

884103 How to obtain the latest MDAC 2.8 service pack

Hotfix information

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft Data Access Components 2.8 service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

File information

The English version of this hotfix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date         Time   Version            Size    File name
   ------------------------------------------------------------------
   22-Jan-2004  08:36  2000.90.736.0     147,456  Dahotfix.exe
   28-Jan-2004  09:00                      4,889  Dahotfix.ini
   28-Jan-2004  09:00                        647  Kb835677_dlvl.inf
   28-Jan-2004  09:00                        641  Kb835677_win2k.inf
   28-Jan-2004  09:00                        733  Kb835677_win2kx.inf
   28-Jan-2004  09:00                        341  Kb835677_winme.inf
   28-Jan-2004  09:00                        855  Kb835677_winmex.inf
   28-Jan-2004  09:00                        603  Kb835677_winxp.inf
   28-Jan-2004  09:00                        907  Kb835677_winxpx.inf
   27-Jan-2004  04:33  2.80.1029.0       147,456  Msdart.dll
   27-Jan-2004  04:34  2000.85.1029.0     24,576  Odbcbcp.dll
   27-Jan-2004  04:33  2.80.1029.0       442,368  Oledb32.dll
   27-Jan-2004  04:33  2000.85.1029.0    503,808  Sqloledb.dll
   27-Jan-2004  04:33  2000.85.1029.0    401,408  Sqlsrv32.dll
Note For a list of all the hotfixes available for MDAC 2.8, click the following article number to view the article in the Microsoft Knowledge Base:

839801 FIX: Hotfixes are available for MDAC 2.8

WORKAROUND

To work around this problem, use the SQL Native Client (SNAC) provider to connect to your instance of SQL Server.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to reproduce the problem

  1. Start SQL Query Analyzer.
  2. Connect to your instance of Microsoft SQL Server 2000.
  3. Run the following Transact-SQL script for creating two tables, a view, and an INSTEAD OF trigger for the INSERT Transact-SQL statements on the view:
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TestInsTrigger]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
    drop trigger [dbo].[TestInsTrigger] 
    GO
    
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VIEW1]') and OBJECTPROPERTY(id, N'IsView') = 1)
    drop view [dbo].[TestView1]
    GO 
    
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[TestTab1]
    GO
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[TestTab2]
    GO 
    
    CREATE TABLE TestTab1
    (
    	Col_1 char(10) PRIMARY KEY CLUSTERED,
    	col_2 char(10)
    )
    GO 
    
    CREATE TABLE TestTab2
    (
    	Col_a char(10) PRIMARY KEY CLUSTERED,
    	Col_b char(10)
    )
    GO 
    
    
    CREATE VIEW TestView1 AS SELECT TestTab1.*, TestTab2.* 
    FROM TestTab1 INNER JOIN TestTab2 
    ON TestTab1.Col_1 = TestTab2.Col_a
    GO
    
    CREATE TRIGGER TestInsTrigger ON TestView1 Instead Of Insert AS 
    Select 'TestInsTrigger trigger fired instead of insert'
    GO
    
    
  4. Create a new Microsoft Visual Basic 6.0 Standard EXE project.
  5. Double-click Form1.
  6. Replace the code in the code window with the following code.

    Note The sample code in this article uses Microsoft ActiveX Data Objects. For this code to run correctly, you must reference the Microsoft ActiveX Data Objects 2.x Library (where 2.x is 2.1 or later). To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft ActiveX Data Objects 2.x Library check box is selected.
    Private Sub Form_Load()
    
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Set cn = New ADODB.Connection
    cn.ConnectionString = "Provider=SQLOLEDB.1; User Id = <User ID>; Password= <Password>; " & _
                          "Initial Catalog=<Database Name>; " & _
                          "Data Source=<SQL Server Instance Name>"
    cn.Open
    
    Set rs = New ADODB.Recordset
    rs.LockType = adLockOptimistic
    rs.CursorLocation = adUseServer
    rs.CursorType = adOpenDynamic
    rs.Open "Select * from TestView1", cn
    
    rs.AddNew
    rs.Fields("Col_1").Value = "Column 1"
    rs.Fields("Col_2").Value = "Column 2"
    rs.Fields("Col_a").Value = "Column 1"
    rs.Fields("Col_b").Value = "Column b"
    
    rs.Update
    rs.Close
    cn.Close
    End Sub
    Note Replace <SQL Server Instance Name> with the name of your instance of SQL Server. Replace <Database Name> with the name of your database where you created the tables, the view, and the trigger. Replace <User ID> with the appropriate user name, and replace <Password> with the appropriate password.
  7. Save the form, and then run the form. You receive the error message that is mentioned in the "Symptoms" section.

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

304096 Trigger does not fire on view when updated through ADO


Modification Type:MajorLast Reviewed:6/22/2006
Keywords:kbHotfixServer kbTrigger kbCursor kbServer kbQFE KbClientServer kbfix KB835677 kbAudDeveloper