Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9010783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:33:17+00:00 2026-06-16T02:33:17+00:00

I have more SQL scripts (each for different version of the application) and I

  • 0

I have more SQL scripts (each for different version of the application) and I want to execute all scripts in one transaction.

I’m executing it from c# using:

ExecuteNonQuery(command, conn, trans) 

on SqlCommand.

The SQL commands in the scripts are separated by GO separators. My C# code iterates through all scripts and creates collection of the SqlCommand based on the GO separator. The GO separator is excluded from SqlCommand execution. It is just a separator in script file.

All was working fine, but I have found one problem. I have in one script the following command:

ALTER TABLE [dbo].[RoleDataPermissions]  WITH NOCHECK ADD  CONSTRAINT     
[FK_RoleDataPermissions_OrganizationUnits] FOREIGN KEY([OrganizationUnitID])
REFERENCES [OrganizationUnits] ([ID])

and in the another script (in another version of app this constraint was deleted) I have:

ALTER TABLE [dbo].[RoleDataPermissions] 
DROP CONSTRAINT FK_RoleDataPermissions_OrganizationUnits

The first command passed fine, but the second one throws the exception:

‘FK_RoleDataPermissions_OrganizationUnits’ is not a constraint. Could not drop constraint. See previous errors.

I’m trying find out what is causing this problem. I think, that the problem is, that if all commands are executed under one transaction, so the first command is not committed and then the second one cannot find this constraint. I have tried also change the isolation level to readuncommited, but it doesn’t help.

Do you have any idea how to deal with this?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:33:18+00:00Added an answer on June 16, 2026 at 2:33 am

    Your analysis is not correct as a transaction can see it’s own uncommitted data. This is easily demonstrated as below.

    CREATE TABLE T1
      (
         ID INT PRIMARY KEY
      )
    
    CREATE TABLE T2
      (
         ID INT
      )
    
    BEGIN TRAN
    
    ALTER TABLE T2
      WITH NOCHECK ADD CONSTRAINT FK_Test FOREIGN KEY(ID) REFERENCES T1
    
    GO
    
    ALTER TABLE T2
      DROP CONSTRAINT FK_Test
    
    COMMIT
    
    DROP TABLE T1, T2 
    

    The syntax you have posted is invalid however so quite likely the constraint isn’t being created due to the syntax error and for some reason the exception isn’t being reported in your application. Or (if your actual syntax is correct) maybe you are dropping the constraint twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database solution project in VS2008 - it generates SQL for more
I have a SQL Server database which has grown to more than 15GB in
I have more than one Event Listener that calls a specific function, and I
I have more or less been able to understand and implement all these concepts
i have more viewcontroller that start from rootviewcontroller. So for example i start with
I have a jquery script that collects data from different sites and saves it
Im creating an IPad Application which will have an SQL Server backend. My question
I have 2 questions regarding performance of PL/SQL script when executing DML. Ofcourse the
The Problem: I want to return all of the rows from the Primary Data
I have more than 100 million unique strings (VARCHAR(100) UNIQUE in MySQL database). Now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.