Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0sql script problem "IDENTITY_INSERT"sql script problem "IDENTITY_INSERT"
Previous
 
Next
New Post
9/10/2007 7:42 PM
 

Hi,

I have a problem with a SQL script and I can't figure a solution.

If I run the script directly in the SQL server, it runs successfully.

But when I install the module on DNN I got this error

Cannot explicit value for identity column in table "table name" when IDENTITY_INSERT is set to OFF

In my code IDENTITY_INSERT is set to on.

The {DataBaseOwner} and {ObjectQualifier} is correctly set.

Any Idea???

Regards
Soft

 
New Post
9/12/2007 12:07 AM
 

Without seeing the SQL.

It would appear that you are trying to INSERT  value into the field you have set to identity.  You cant do this.

Can you maybe post the SQL.

Westa

 
New Post
9/12/2007 6:17 AM
 

this is a simplified version of my script.

this script work under SQL (if I replace {databaseOwner} and {objectQualifier})
In DNN does not work.

any idea?



CREATE TABLE {databaseOwner}Tmp_{objectQualifier}table_item
    (
    ModuleID int NOT NULL,
    itemid int NOT NULL IDENTITY (1, 1),
    itemdescription varchar(2000) NULL
    )  ON [PRIMARY]
GO
SET IDENTITY_INSERT {databaseOwner}Tmp_{objectQualifier}table_item ON
GO
IF EXISTS(SELECT * FROM {databaseOwner}{objectQualifier}table_item)
     EXEC('INSERT INTO {databaseOwner}Tmp_{objectQualifier}table_item (ModuleID, itemid, itemdescription)
        SELECT ModuleID, itemid, itemdescription  FROM {databaseOwner}{objectQualifier}table_item WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT {databaseOwner}Tmp_{objectQualifier}table_item OFF
GO
DROP TABLE {databaseOwner}{objectQualifier}table_item
GO
EXECUTE sp_rename N'{databaseOwner}Tmp_{objectQualifier}table_item', N'{objectQualifier}table_item', 'OBJECT'
GO

 
New Post
9/12/2007 2:17 PM
 

I am not sure about this but my guess would be that DNN is executing each statement in its own transaction, thus your turning on of Identity_insert is not working...


-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
9/16/2007 11:34 AM
 

your right thanks

from

CREATE TABLE {databaseOwner}Tmp_{objectQualifier}table_item
    (
    ModuleID int NOT NULL,
    itemid int NOT NULL IDENTITY (1, 1),
    itemdescription varchar(2000) NULL
    )  ON [PRIMARY]
GO
SET IDENTITY_INSERT {databaseOwner}Tmp_{objectQualifier}table_item ON
GO
IF EXISTS(SELECT * FROM {databaseOwner}{objectQualifier}table_item)
     EXEC('INSERT INTO {databaseOwner}Tmp_{objectQualifier}table_item (ModuleID, itemid, itemdescription)
        SELECT ModuleID, itemid, itemdescription  FROM {databaseOwner}{objectQualifier}table_item WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT {databaseOwner}Tmp_{objectQualifier}table_item OFF
GO
DROP TABLE {databaseOwner}{objectQualifier}table_item
GO
EXECUTE sp_rename N'{databaseOwner}Tmp_{objectQualifier}table_item', N'{objectQualifier}table_item', 'OBJECT'
GO

 

to this

CREATE TABLE {databaseOwner}Tmp_{objectQualifier}table_item
    (
    ModuleID int NOT NULL,
    itemid int NOT NULL IDENTITY (1, 1),
    itemdescription varchar(2000) NULL
    )  ON [PRIMARY]
GO
SET IDENTITY_INSERT {databaseOwner}Tmp_{objectQualifier}table_item ON
              
IF EXISTS(SELECT * FROM {databaseOwner}{objectQualifier}table_item)
     EXEC('INSERT INTO {databaseOwner}Tmp_{objectQualifier}table_item (ModuleID, itemid, itemdescription)
        SELECT ModuleID, itemid, itemdescription  FROM {databaseOwner}{objectQualifier}table_item WITH (HOLDLOCK TABLOCKX)')

SET IDENTITY_INSERT {databaseOwner}Tmp_{objectQualifier}table_item OFF
GO
DROP TABLE {databaseOwner}{objectQualifier}table_item
GO
EXECUTE sp_rename N'{databaseOwner}Tmp_{objectQualifier}table_item', N'{objectQualifier}table_item', 'OBJECT'
GO

 

now it's working fine thansk you

Regards
Soft

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0sql script problem "IDENTITY_INSERT"sql script problem "IDENTITY_INSERT"


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out