URGENT Cannot insert duplicate key in object 'dbo.sf_pa

Posted by Community Admin on 04-Aug-2018 20:58

URGENT Cannot insert duplicate key in object 'dbo.sf_page_templates'

All Replies

Posted by Community Admin on 23-Sep-2013 00:00

Hi, all
I have a little experience in .NET Framework. I have this project build upon.NET using Sitefinity. since two days and suddenly the website stop working and gave this error "Violation of PRIMARY KEY constraint 'pk_sf_page_templates'. Cannot insert duplicate key in object 'dbo.sf_page_templates'.
The statement has been terminated." 
and I have no idea what is that ??

Sorry of my bad English. and please consider this is an urgent ):
Stack Trace:
[SQLException: Violation of PRIMARY KEY constraint 'pk_sf_page_templates'. Cannot insert duplicate key in object 'dbo.sf_page_templates'.
The statement has been terminated.]
Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute() +344
OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute() +77
OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes) +1832

[DuplicateKeyException: Insert of '1712689138-f669d9a7-009d-4d83-bbbb-000000000001' failed: Telerik.OpenAccess.RT.sql.SQLException: Violation of PRIMARY KEY constraint 'pk_sf_page_templates'. Cannot insert duplicate key in object 'dbo.sf_page_templates'.
The statement has been terminated.
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
INSERT INTO [sf_page_templates] ([description_], [keywords_], [title_], [app_name], [buffer_output], [cache_duration], [cache_output], [can_inherit_permissions], [category], [culture], [enable_event_validation], [enable_session_state], [enable_theming], [enable_view_state], [enable_view_state_mac], [error_page], [framework], [id], [include_script_manger], [inherits_permissions], [is_personalized], [ky], [last_control_id], [last_modified], [locked_by], [maintain_scroll], [master_page], [nme], [ordinal], [ownr], [prent_template_id], [personalization_master_id], [personalization_segment_id], [require_ssl], [response_encoding], [show_in_navigation], [sliding_expiration], [smart_navigation], [theme], [ui_culture], [validate_request], [vrsion], [view_state_encryption], [voa_version]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(set event logging to all to see parameter values)]
DynamicModule.ns.Wrapped_OpenAccessPageProvider_cbafa4c072f7412d94339a725f2c9054.GetSecurityRoot() +162
Telerik.Sitefinity.Data.ManagerBase`1.GetSecurityRoot() +29
Telerik.Sitefinity.Abstractions.SiteInitializer.CreateBackendRoot() +789
Telerik.Sitefinity.Abstractions.SiteInitializer.InstallDefaults() +55
Telerik.Sitefinity.Services.SystemManager.Initialize() +331
Telerik.Sitefinity.Abstractions.Bootstrapper.RegisterRoutes() +627
Telerik.Sitefinity.Abstractions.Bootstrapper.Bootstrap() +281
Telerik.Sitefinity.Web.SitefinityHttpModule.Init(HttpApplication context) +116
System.Web.Routing.UrlRoutingModule.System.Web.IHttpModule.Init(HttpApplication application) +10
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +517
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253

[HttpException (0x80004005): Insert of '1712689138-f669d9a7-009d-4d83-bbbb-000000000001' failed: Telerik.OpenAccess.RT.sql.SQLException: Violation of PRIMARY KEY constraint 'pk_sf_page_templates'. Cannot insert duplicate key in object 'dbo.sf_page_templates'.
The statement has been terminated.
at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute()
at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute()
at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes)
INSERT INTO [sf_page_templates] ([description_], [keywords_], [title_], [app_name], [buffer_output], [cache_duration], [cache_output], [can_inherit_permissions], [category], [culture], [enable_event_validation], [enable_session_state], [enable_theming], [enable_view_state], [enable_view_state_mac], [error_page], [framework], [id], [include_script_manger], [inherits_permissions], [is_personalized], [ky], [last_control_id], [last_modified], [locked_by], [maintain_scroll], [master_page], [nme], [ordinal], [ownr], [prent_template_id], [personalization_master_id], [personalization_segment_id], [require_ssl], [response_encoding], [show_in_navigation], [sliding_expiration], [smart_navigation], [theme], [ui_culture], [validate_request], [vrsion], [view_state_encryption], [voa_version]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(set event logging to all to see parameter values)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9009356
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256

Posted by Community Admin on 25-Sep-2013 00:00

any ideas of whats happening ??

Posted by Community Admin on 25-Sep-2013 00:00

Hi Hadi, 
I'm new to Sitefinity but I can tell you what the error message means. (because I design databases and work with ASP.NET code)

1. The error message is coming from the database (e.g. MS SQL Server)
2. You can think of the database as a set of tables with links between the database tables and the other code that protects what is called "database integrity" .
3. It is usual for each table not to allow duplicate entries. (A table's primary key is used for this).
4. So what the error message means is this:
- The Sitefinity database contains a table called  dbo.sf_page_templates  
- Whoever designed the Sitefinity database set a primary key in this table in order to prevent duplicate rows from being inserted.
-  INSERT INTO is the SQL command that  acts to add new rows into one or more tables. (there are two instances of INSERT INTO in your error message)
- the causes of this problem can be understood by a person who understands the way the Sitefinity database has been designed (I'm new to Sitefinity so I don't understand the database design. )  

5. I might be wrong on this but it seems to me that the cause of your problem might be something like::
- The Sitefinity code (that which is not within the database) is allowing users to enter transactions that request changes to the database but the transaction content is not allowed by the database.
- It may be that the Sitefinity User Guide describes things that users should not do because they will cause problems (like this one).
- it may be that there is a mismatch between the database design and the code which is outside the database.  (e.g, the code that creates what you see in your browser.)

I know that this answer does not solve your problem but I hope it has helped you to get a better understanding of what is happening here.

Good luck with this
Ken Evans

Posted by Community Admin on 25-Sep-2013 00:00

Hi Ken,
1st would like to thank you for this explanations.
2nd as I understand its a DB issue. but I don't know how to solve it, is it C# issue or DB ):

Posted by Community Admin on 25-Sep-2013 00:00

Well, from what I can see from your post it seems to me that it is one of the following:
1 - The database design is faulty
2 - The OO code that interacts with the database is faulty
3 - You made a mistake in trying to do something that the Sitefinity user manual says is "not allowed".

It's up to the Sitefinity deve1opment team to fix 1 and/or 2  - if indeed they are broken.

So what we can discuss here is point 3.  What was it that you did that caused the error?
- are you just trying to add content?
- or are you using Visual Studio to extend the scope of Sitefinity?
Ken

Posted by Community Admin on 25-Sep-2013 00:00

well, I haven't tried to add any content or change anything. My work is only in the Master files I open it through Sublime IDE to add some design stuff. Even I don't have a VB in my machine to run this project. so what the reason behind this problem ?? its suddenly happened I even can not access the control panel of Sitefinity

Posted by Community Admin on 25-Sep-2013 00:00


When you say "Sublime IDE" do you mean this: ? en.wikipedia.org/.../Sublime_Text

I don't understand this sentence: " Even I don't have a VB in my machine to run this project"
By "VB" do you mean "Visual Studio"?  en.wikipedia.org/.../Microsoft_Visual_Studio or something else?

Anyway, you said: "My work is only in the Master files I open it through Sublime IDE to add some design stuff."
OK - I suspect that you have changed something in a master file that has wrecked the Sitefinity system.

As I mentioned, I only started working with Sitefinity yesterday and I'm still learning so treat the following with caution:
Here is some stuff that seems  relevant to your problem (from what I have learned so far:)
1: Sitefinity is "dynamic"  This means that much of what you might see as code has probably been "generated" from the database. It's not "static" like an HTML page that you can edit directly.
To change Sitefinty functionality (which is what you are doing) you have to make the changes in a way that means that they are stored in the Sitefinity database.

2: The cause of your problem:
As we know from the error message, the table that caused your error is called sf_page_templates.
This table contains 41 columns and I have attached a file that shows the content of this table.

What I suggest that you do is to look at the names of the columns in the table and see if any of the column names relate to what you were trying to do with what you called the "Sublime IDE" and then post a message here that describes what you find.

By the way, Sitefinity offers a free editor called "Thunder".
This is an "Add in" for Microsoft's  IDE called "Visual Studio" and amongst many other things, it contains a Website Template editor .

Unfortunately, Thunder does not work with the free version of Visual Studio so you have to buy Visual Studio in order to use the "free Thunder.
 
Hope this helps

Ken

Posted by Community Admin on 25-Sep-2013 00:00

Sorry Ken my bad for this confusion
Yes Sublime text as an editor and I meant by VB which Visual Studio.
Yes as I said my work is only in the master files and I only added social media icons in the header 15 days ago and it worked fine, the day where this error happened I opened Home.master by Sumblime using FTP software FileZila  and I did not change anything or add any thing then I closed the file and quit FTP .After a  while the error came so i don't know if something went wrong when I opened Home.Master. because I just open it i did not change any or add any or even click save. I looked at sf_page_templates and it has pk_sf_page_templates as primary key which is the ID of the table. what I understood from the error that its trying to insert a new row into this table and the value of the ID  is duplicated. I could not know what is the duplicated value of the pk_sf_page_templates so I can know the row ):
do you know how dbo.sf_page_templates tables works?  and if can tell me where is the C# file that trying to insert this row.

Posted by Community Admin on 26-Sep-2013 00:00

Thanks for the explanation.

Each value in a uniqueidentifier column is a 16 byte GUID that looks like this:
f669d9a7-009d-4d83-bbbb-000000000009

So "something" tried to insert a new row into the "table sf_page_templates"
and that new row had the same value in the ID column as an existing row.
So our challenge is to find this "something" and then see how it relates to what you did.

I have taken a closer look at the database and I can't see any code in there that would do this.
So I'll have to take a closer look at the non-database code. There is quite a lot of code so it may take me a while to study it using Visual Studio.

Ken




Posted by Community Admin on 26-Sep-2013 00:00

yes ken I have noticed that about the 16 byte. I think something related to none-database code also I saw these number in the ID column are also exist in a another table called sf_pages_permissions something like that this table have just two columns ID and ID_2

Posted by Community Admin on 26-Sep-2013 00:00

Last night I looked through the code using Visual Studio. I expected to be able to search for the table name in the code. Unfortunately, I could not find it so I'm stuck..

I have been dealing with open source asp.net/sql server websites for the last 7 years.
I may be wrong but it seems to me that the Sitefinity code is compiled code - which I don't know how to search- or even if it is practical to search the code.

Have you considered posting a support ticket about this problem?
I'm still on day 2 of my 30 day trial so I can post support tickets for the next 28 days.

Which version are you running?
  

Posted by Community Admin on 26-Sep-2013 00:00

Hello,

The cause of the error "Cannot insert duplicate key in object 'dbo.sf_page_templates" is that the site have incorrect configuration files used. The configuration files are stored in App_Data/Sitefinity/Configuration/ are not the configuration files for the site and this the site can`t start because without the configuration files this error is thrown.

Please make sure the latest changes made to the site project files and mainly the configurations don`t remove or edit some configuration files.
Configuration files are site specific they contain the settings for the data stored in the database and go hand in hand with it. The configurations are site specific and can`t be regenerated on demand.


Regards,
Stanislav Velikov
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed