On a fresh install Kentico tries to create my database a second time

Stephen Price asked on September 14, 2016 18:06

I have a fresh install of Kentico 8.2. I'm trying to create a local dev instance of our staging site. I just want to get to where I can import the site package to my local instance. Currently, when I visit the /Admin route on my local instance, I get redirected to cmsinstall/install.aspx and see the following a database creation dialog. Every field is disabled and its trying to install into the database that was created and populated when I ran the .exe installer. So, with no other options available to me I click ahead.

When the Kentico instance inexplicably tries to create all new tables over the already existing ones, I get the inevitable error:

ERROR: An error occurred: [DataConnection.HandleError]: 

    [ResourceID] [int] IDENTITY(1,1) NOT NULL,
    [ResourceDisplayName] [nvarchar](100) NOT NULL,
    [ResourceName] [nvarchar](100) NOT NULL,
    [ResourceDescription] [nvarchar](max) NULL,
    [ShowInDevelopment] [bit] NULL,
    [ResourceURL] [nvarchar](1000) NULL,
    [ResourceGUID] [uniqueidentifier] NOT NULL,
    [ResourceLastModified] [datetime2](7) NOT NULL,
    [ResourceIsInDevelopment] [bit] NULL,
    [ResourceHasFiles] [bit] NULL,
    [ResourceVersion] [nvarchar](200) NULL,
    [ResourceAuthor] [nvarchar](200) NULL 
    ADD CONSTRAINT [DEFAULT_CMS_Resource_ResourceHasFiles] DEFAULT ((0)) FOR [ResourceHasFiles] 
    ADD CONSTRAINT [DEFAULT_CMS_Resource_ShowInDevelopment] DEFAULT ((0)) FOR [ShowInDevelopment] 
    CREATE CLUSTERED INDEX [IX_CMS_Resource_ResourceDisplayName] ON [CMS_Resource] ([ResourceDisplayName]) 
    CREATE NONCLUSTERED INDEX [IX_CMS_Resource_ResourceName] ON [CMS_Resource] ([ResourceName]) 

Caused exception: There is already an object named 'CMS_Resource' in the database. 
    at CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, Exception ex) 
    at CMS.DataEngine.AbstractDataConnection.ExecuteQuery(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction) 
    at CMS.DataEngine.SqlInstallationHelper.RunSQLQuery(String query, IDataConnection conn, String dbSchema) 
    at CMS.DataEngine.SqlInstallationHelper.RunSQLScript(String fileName, IDataConnection conn, String dbSchema)

Why on earth is it even trying to create a db when there's already a fully populated one its already pointed at? More importantly, how do I get it to stop?!

For context, my install options:

  • Custom,
  • Web App,
  • Installed to a preexisting empty database on my local SQL Server 2012 instance
  • connection string: "Data Source=localhost;Initial Catalog=Kentico;Integrated Security=True;User ID=;Password=;Connect Timeout=60"
  • IIS site bound to wwwroot/Kentico/CMS
  • Application pool Identity set to LocalSystem
  • NT_AUTHORITY/SYSTEM is added to the db with full permissions.

Correct Answer

Stephen Price answered on September 14, 2016 23:47

Sorry fellas none of those suggestions would have helped, but thanks anyway.

It turns out I had to set the Kentico instance's Application Pool Identity to NetworkService. Then I had to add NT AUTHORITY\NETWORKSERVICE as a user in SSMS and give it db_owner privileges on the Kentico database. Simple, but if you don't know what you're looking for, the clues are few and far between.

Turns out that last bullet point (the wrong db user) on my setup options listed above coupled with the settings of the autogenerated app pool that the Kentico installer makes were the giveaways that led me to the fix.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on September 14, 2016 18:19

If you just want to connect that new code base to an existing database, you need to enter the connection string in the web.config. If you want to have a new (second) site in your existing code base, there is no need to create a new instance of Kentico, just go through the UI and add a new site.

If you already had a new database created and all the Kentico objects in it AND it's still trying to create a new database then your install must have failed. I'd remove the database, code base and ensure the user creating the database has create database access and is the db owner.

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on September 14, 2016 21:11

Brenden suggestion should resolve your issue, but in case there is something wrong with that installation/code base, I'd download Kentico installer and try this once again from scratch. Installer gives you all possible options for installation: local vs. remote, web app vs. web site, pre-installed site, etc.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on September 14, 2016 23:53

Unless you set the defaults for your app pools and websites, whenever an app pool is created (automatically like Kentico did or manually) it will use those defaults in the .config file on your machine. So not a Kentico thing but a setup thing from your machine.

Nice job figuring it out and posting the solution.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.