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

HomeHomeGetting StartedGetting StartedInstalling DNN ...Installing DNN ...SQL Foreign Key Problem with 4.0.3 to 4.3.5 upgradeSQL Foreign Key Problem with 4.0.3 to 4.3.5 upgrade
Previous
 
Next
New Post
9/20/2006 9:50 AM
 

Hello, I attempted a test upgrade of my 4.0.3 site to 4.3.5 and had 2 apparently related errors in 2 different SQL upgrade scripts. Before I attempt to resolve, I am wondering if anyone else has seen the same or similar error and what a possible resolution is.

In the 04.00.04.log file it indicates an error altering the Folders table

System.Data.SqlClient.SqlException: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_{objectqualifier}Files_{objectqualifier}Folders". The conflict occurred in database "DBName", table "dbo.{objectqualifier}Folders", column 'FolderID'.

Using this SQL:

If (SELECT {databaseOwner}{objectQualifier}fn_GetVersion(3,2,3)) = 0
 BEGIN
  ALTER TABLE {databaseOwner}{objectQualifier}Files ADD CONSTRAINT
   FK_{objectQualifier}Files_{objectQualifier}Folders FOREIGN KEY
   (
   FolderID
   ) REFERENCES {databaseOwner}{objectQualifier}Folders
   (
   FolderID
   )
 END

And in the 4.03.01 log:

System.Data.SqlClient.SqlException: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_{objectqualifier}Files_{objectqualifier}Folders". The conflict occurred in database "DBName", table "dbo.{objectqualifier}Folders", column 'FolderID'.

Using this SQL:

/* This tries to apply a foreign key on the files/folders tables */
/*****************************************************************/

IF NOT EXISTS ( SELECT * FROM sysobjects WHERE id = object_id(N'FK_{objectQualifier}Files_{objectQualifier}Folders') AND OBJECTPROPERTY(id, N'IsForeignKey') = 1)
 BEGIN
  ALTER TABLE {databaseOwner}{objectQualifier}Files ADD CONSTRAINT
   FK_{objectQualifier}Files_{objectQualifier}Folders FOREIGN KEY
   (
   FolderID
   ) REFERENCES {databaseOwner}{objectQualifier}Folders
   (
   FolderID
   )
 END

Any thoughts or recommendations are appreciated.

Thank you,

Rob Ralston


Rob Ralston, SilverBullet Technologies LLC, www.silverbullettech.com
 
New Post
9/20/2006 10:07 PM
 

Hi, still looking for ideas here.

Thanks,

Rob Ralston


Rob Ralston, SilverBullet Technologies LLC, www.silverbullettech.com
 
New Post
9/26/2006 6:57 PM
 
G'day Rob.
Yes I just did the same upgrade yesterday and got the same errors?
e.g. 04.00.04.log


System.Data.SqlClient.SqlException: ALTER TABLE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_Files_Folders'. The conflict occurred in database 'DNN_SmartSpeak_Dev', table 'Folders', column 'FolderID'.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at DotNetNuke.Data.SqlDataProvider.ExecuteADOScript(String SQL)
   at DotNetNuke.Data.SqlDataProvider.ExecuteScript(String Script, Boolean UseTransactions)

If (SELECT dbo.fn_GetVersion(3,2,3)) = 0
    BEGIN
        ALTER TABLE dbo.Files ADD CONSTRAINT
            FK_Files_Folders FOREIGN KEY
            (
            FolderID
            ) REFERENCES dbo.Folders
            (
            FolderID
            )
    END



I have only upgraded my development site.
Did you find a fix and do the errors stop any parts of the site from working? I don't want to upgrade my prodution site if the errors will bring it down.

Anyone else encountered this problem?
 
New Post
9/27/2006 5:30 AM
 

I got the same thing doing a 3.1.1 -> 4.3.5 upgrade last weekend. The source of the problem is that there are records in the Files table where the Folder value does not match with any records in the Folders table.

Assuming you are able to run SQL queries against your DB, you can run this to find out the offending records:

select *
from Files
where folder not in (
select
 case when folderpath = '' then ''
 when folderpath not like '%/' then folderpath + '/'
 else folderpath
 end
from folders
)

Then I guess you could fix the problem by creating the folders that are indicated in the Folder column through File Manager. I solved the problem by adding records to the Folders table like this:

insert folders (portalid, folderpath)
select distinct portalid, folder
from Files
where folder not in (
select
 case when folderpath = '' then ''
 when folderpath not like '%/' then folderpath + '/'
 else folderpath
 end
from folders
)

The upgrade then completed successfully.

 
New Post
9/27/2006 6:47 AM
 

Cheers from Germany,
Sebastian Leupold

dnnWerk - The DotNetNuke Experts   German Spoken DotNetNuke User Group

Speed up your DNN Websites with TurboDNN
 
Previous
 
Next
HomeHomeGetting StartedGetting StartedInstalling DNN ...Installing DNN ...SQL Foreign Key Problem with 4.0.3 to 4.3.5 upgradeSQL Foreign Key Problem with 4.0.3 to 4.3.5 upgrade


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