'Invalid Column Name' Error

  • I've looked for the last two days trying to figure this out and no other solutions or posts seem to work or apply to my problem.

    I have recreated this SQL Express database three times. The first time, I scripted it from another database, and the last two times, I started from scratch and still get the same error.

    I am using this query:

    SELECT

    dbo.shops.bizID,

    dbo.shops.bizName,

    dbo.shops.bizPhone,

    dbo.shops.bizURL,

    dbo.shops.bizLogo

    FROM

    dbo.bizInCat

    INNER JOIN dbo.Category ON (dbo.bizInCat.catID = dbo.Category.catID)

    INNER JOIN dbo.shops ON (dbo.bizInCat.bizID = dbo.shops.bizID)

    WHERE

    dbo.shops.bizState = @state AND

    dbo.shops.bizCity = @city AND

    dbo.shops.bizActive = 'True' AND

    dbo.Category.catName = @category

    I KNOW that the columns bizState and bizCity exist. If I run the query in SSMS either on my local machine, or on the server, it works. It also worked when I plugged it into MS SQL Code Factory. But it will not work when ran in visual web developer, or running the application in the production environment. I always get the Invalid Column Name error for bizState and bizCity. If I remove those two constraints from the where clause, it works in both web developer and live on the production server.

    Can anyone explain to me what is going on with these two columns? I've tried Ctrl+Shift+R, rebooting the server, recreating the DataSet in developer and nothing seems to work. This is driving me nuts! It's a pretty simple app and database query!

    Thanks in advance...

  • Can you post the CREATE TABLE statement for the Shops table please?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I used the auto generated one from SSMS

    USE [DB_CW01_SiHu]

    GO

    /****** Object: Table [dbo].[shops] Script Date: 01/12/2012 13:00:19 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE TABLE [dbo].[shops](

    [bizID] [int] IDENTITY(1,1) NOT NULL,

    [bizName] [nvarchar](255) NULL,

    [bizPhone] [nvarchar](15) NULL,

    [bizURL] [nvarchar](500) NULL,

    [bizLogo] [nvarchar](max) NULL,

    [clicks] [int] NULL,

    [clickReset] [datetime] NULL,

    [clickTotal] [int] NULL,

    [bizActive] [bit] NOT NULL,

    [bizCreated] [datetime] NULL,

    [bizRate] [decimal](18, 0) NULL,

    [lastPayment] [datetime] NULL,

    [userID] [uniqueidentifier] NULL,

    [contactName] [nvarchar](250) NULL,

    [contactEmail] [nvarchar](250) NULL,

    CONSTRAINT [PK_shops] PRIMARY KEY CLUSTERED

    (

    [bizID] ASC

    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[shops] ADD CONSTRAINT [DF_shops_bizActive] DEFAULT ('False') FOR [bizActive]

    GO

  • That table doesn't have either of the columns bizState or bizCity.

    With that definition, the query is going to give an Invalid column error because the two columns are not in the table.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • They were added to the new table in the new database after it was scripted. That's where I said I re-built the database manually two times, no scripting, but actually going through and creating each column (including the city and state columns), type etc.

    I am in the process of starting a new project in web developer and see how far I can get so I can figure out where the hitch is.

  • dcwhitson (1/12/2012)


    They were added to the new table in the new database after it was scripted. That's where I said I re-built the database manually two times, no scripting, but actually going through and creating each column (including the city and state columns), type etc.

    But the table that you scripted for me (which I assume is the actual, latest, real table that you are using) doesn't have them. Was that the new table in the new database? If so, the columns aren't there. If it wasn't, please post the CREATE TABLE statement for the actual, real shops table that you are running that query against

    I am in the process of starting a new project in web developer and see how far I can get so I can figure out where the hitch is.

    No, don't. There's a logical explanation here, trashing and restarting could just waste time.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply