Results 1 to 12 of 12

Thread: [RESOLVED] some tables not allowing update/insert

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Resolved [RESOLVED] some tables not allowing update/insert

    So I have MSSQL Version 8 (I think that's 2003). This database is used with an old .NET application that I'm currently rewriting in PHP. Most of that is irrelevant, however.

    I use one user to do all the work against the database. I can SELECT data from any table without problems. I can run UPDATE and INSERT statements against some of the tables. But there are a few tables where I cannot run UPDATE or INSERT statements from my application. I always get this error:

    Incorrect syntax near the keyword 'and'.

    Even when I don't have an "and" in my WHERE clause!? I can run the query directly in the database from Enterprise Manager without any issues, but I get the above when running from my application on those specific tables. I don't see any obvious differences between the tables that would cause this problem.

    Can anyone shed any light on this issue?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: some tables not allowing update/insert

    Can you show us the SQL statements, and the name of one of the tables and the fields in it.

    So I have MSSQL Version 8 (I think that's 2003).
    It is 2000.

  3. #3

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: some tables not allowing update/insert

    SQL statement: UPDATE DTPROJECTTRACKING SET Time_Unit = 1 WHERE CONTRACT_ID = '08132'

    Here is the table:
    Code:
    CREATE TABLE [dbo].[DTPROJECTTRACKING] (
    	[Contract_ID] [nchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    	[Contract_serial_No] [int] NOT NULL ,
    	[Project_ID] [nchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    	[Service_ID] [nchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    	[Time_Unit] [nchar] (15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Work_Complete] [decimal](18, 4) NULL ,
    	[GPR] [decimal](18, 2) NULL ,
    	[GER] [decimal](18, 2) NULL ,
    	[Yr] [nchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    	[WriteOff] [decimal](18, 4) NULL ,
    	[Billable] [decimal](18, 4) NULL ,
    	[GPR_in_work_units] [decimal](18, 4) NULL ,
    	[Tracked_Units] [decimal](18, 4) NULL ,
    	[Revenue_Units] [decimal](18, 4) NULL ,
    	[Mon] [nchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
    	[Exported] [bit] NULL ,
    	[end_user_login] [nchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[Modified] [bit] NULL ,
    	[Discount_Value] [decimal](18, 2) NULL ,
    	[Mtnc_Value] [decimal](18, 2) NULL ,
    	[comment] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[unbilled_Tracked_Bill] [decimal](18, 4) NULL ,
    	[unbilled_Bill_rev] [decimal](18, 4) NULL ,
    	[consumed_unbilled] [decimal](18, 4) NULL ,
    	[unbilled] [decimal](18, 4) NULL ,
    	[reason_unbilled] [nchar] (128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    	[reasoncode_unbilled] [nchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
    ) ON [PRIMARY]
    GO
    I didn't design the table so please ignore the crappy configuration.

    Thanks for your help, please let me know if you need anything else!
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: some tables not allowing update/insert

    And if it helps, I'm using a global sa role in my connection string.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: some tables not allowing update/insert

    Look to see if there are any triggers on the table... that's the only thing I can think of that would explain why some tables work and others don't. I bet there is a buggy trigger that's firing off.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: some tables not allowing update/insert

    Hmm... didn't think of that. There are 43 stored procedures in the DB... any way to query those without looking through all 43??
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: some tables not allowing update/insert

    Oh wait, you meant trigger... not SP. Looking at the one trigger now.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  8. #8
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: some tables not allowing update/insert

    You mean search the stored procedures for the table? If so:

    ----Option 1
    SELECT DISTINCT so.name
    FROM syscomments sc
    INNER JOIN sysobjects so ON sc.id=so.id
    WHERE sc.TEXT LIKE '%yourtable%'
    ----Option 2
    SELECT DISTINCT o.name, o.xtype
    FROM syscomments c
    INNER JOIN sysobjects o ON c.id=o.id
    WHERE c.TEXT LIKE '%YourTable%'

    Credit for those goes here:

    http://blog.sqlauthority.com/2006/12...red-procedure/

  9. #9
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: some tables not allowing update/insert

    Quote Originally Posted by ober0330 View Post
    Oh wait, you meant trigger... not SP. Looking at the one trigger now.
    Oops...too slow

  10. #10

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: some tables not allowing update/insert

    I wasted a ton of time on this yesterday.. should have come here first. It was the trigger. Thank you all!
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] some tables not allowing update/insert

    That's one reason I hate triggers... there isn't anything obvious to say that there is one... you have to intentionally go looking for it... and the error messages NEVER tell you that the error was in a trigger... just that there was "an error" ... At least you only lost a day.... I once lost a week because someone added a trigger and didn't document it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Re: [RESOLVED] some tables not allowing update/insert

    The crazy thing is that the functionality provided by the trigger is both inefficient and bad design. So add bad design on top of a flawed method of getting work done and you create a nightmare.

    Thanks again for the suggestion!
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width