Attatching a Content DB to a Web Application

On February 13, 2009, in SharePoint 2007, by shereen

For each Web Application you create in SharePoint, by default, there is a single Content DB that is assigned to it. Typically, the steps for creating a web application are as follows:

  1. Launch your Central Administration web site.
  2. On the Quick Launch bar to the left of the page, click on Application Management.
  3. Under the SharePoint Web Application Management heading, click on Create or extend Web application.
  4. Click on Create a new Web Applicaiton.
  5. The Create New Web Application page requires some information before creating your new web application. I won’t go through all of this in detail, but let’s pay particular attention to the Database Name and Authentication section. I have attempted in the past to alter the database name to match the already existing content db i would like this web application to use. This is not recommended nor does it work consistently. What you’ll want to do is accept all defaults for the database name and proceed with creating your web application. In the next steps we’ll outline how you swap this content db out for the one your already existing content db.

Now once your content db has been created, you’ll need to go back to the Application Management screen. From there, try the following:

  1. Click on Content databases.
  2. On the right of the toolbar, look for the Web Application drop down. Make sure you change this to match the web app you’re trying to replace the content db for. I find that sometimes this is defaulted to the Central Admin web application which is not what we want.
  3. Click on the database name link, this should bring up the Manage Content Database Settings page. Change your Database status to Offline and check Remove content database. Click OK. This content db shouldn’t contain anything since we just created this web application.
  4. We should now be redirected back to the Manage Content Databases page. Click on Add a content database.
  5. The only thing you need to change on this page is the Database Name field. Set this to the name of the content db you want to add. Set the search server and click OK.

Now typically this is a smooth operation, however, if you encounter the error below:

Attaching this database requires an upgrade, which could time out the browser session. You must use the STSADM command ‘addcontentdb’ to attach this database.

Open up a command prompt window, and type the following stsadm command in:

stsadm -o addcontentdb -url http://server01/ -databasename WSS_Content

There are other arguments you can use for this command, to see a list of those, type:

stsadm -o addcontentdb

Once the command has completed successfully, try loading your site. If you have any issues at all with this, drop me a line.

Tagged with:  

2 Responses to “Attatching a Content DB to a Web Application”

  1. Vinit says:

    Hi,
    After running addcontentdb command i am getting error that
    “Upgrade completed with errors: review the upgrade.log file”. i am writing some last lines of upgrade.log file. Please help.

    [SPContentDatabaseSequence] [DEBUG] [7/23/2011 10:30:07 AM]: Calling get SchemaVersion on Database Navigate_ContentDB, Status = Upgrading.
    [SPContentDatabaseSequence] [DEBUG] [7/23/2011 10:30:07 AM]: Executing database object restore script.
    [SPUtility] [DEBUG] [7/23/2011 10:30:07 AM]: File C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Template\sql\storeup.sql, Time out = 9848 sec
    [SPManager] [ERROR] [7/23/2011 10:30:14 AM]: Upgrade [SPContentDatabase Name=Navigate_ContentDB Parent=SPDatabaseServiceInstance] failed.
    [SPManager] [ERROR] [7/23/2011 10:30:14 AM]: A severe error occurred on the current command. The results, if any, should be discarded.
    The statement has been terminated.
    [SPManager] [ERROR] [7/23/2011 10:30:14 AM]: at System.Data.SqlClient.SqlConnection.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 Microsoft.SharePoint.Utilities.SqlSession.ExecuteScript(TextReader textReader, Int32 commandTimeout)
    at Microsoft.SharePoint.Utilities.SqlSession.ExecuteScript(String path, Int32 commandTimeout)
    at Microsoft.SharePoint.Upgrade.SPUtility.ExecuteSqlFile(SqlSession sqlSession, ISqlSession isqlSession, SqlFile sqlFileId, Int32 timeOut)
    at Microsoft.SharePoint.Upgrade.SPUtility.ExecuteSqlFile(SqlSession sqlSession, SqlFile sqlFileId, Int32 timeOut)
    at Microsoft.SharePoint.Upgrade.SPContentDatabaseSequence.Upgrade()
    at Microsoft.SharePoint.Upgrade.SPManager.Upgrade(Object o, Boolean bRecurse)
    [SPManager] [DEBUG] [7/23/2011 10:30:14 AM]: Elapsed time upgrading [SPContentDatabase Name=Navigate_ContentDB Parent=SPDatabaseServiceInstance]: 00:00:08.
    [SPManager] [INFO] [7/23/2011 10:30:14 AM]: Resetting the status of PersistedUpgradableObject: SPContentDatabase Name=Navigate_ContentDB Parent=SPDatabaseServiceInstance to Online.
    [SPManager] [DEBUG] [7/23/2011 10:30:14 AM]: Using cached [SPContentDatabase Name=Navigate_ContentDB Parent=SPDatabaseServiceInstance] NeedsUpgrade value: True.
    [SPManager] [DEBUG] [7/23/2011 10:30:14 AM]: Using cached [SPContentDatabase Name=WSS_Content_adfb8f46eeab4c04a266d14a0aa88ac3 Parent=SPDatabaseServiceInstance] NeedsUpgrade value: False.
    [SPManager] [INFO] [7/23/2011 10:30:14 AM]: Inplace Upgrade session finishes. root object = SPContentDatabase Name=Navigate_ContentDB Parent=SPDatabaseServiceInstance, recursive = False. 1 errors and 0 warnings encountered.

  2. shereen says:

    can you email me the entire log file if it’s not too big? shereen at qumsieh dot ca.

Leave a Reply