Sharepoint 2007 DirectoryNotFoundException

Yesterday we were working on one of the site-collection and it was having some issues on the performance side, although we did all the required Performance tunning stuff, we couldnt get it to perform. Also that was in the Stage environment so finally we decided to Create the web-app again and then attach the content databse (old that has this site collection), so we did all the needed steps for creating the web-app and deploying the solutions again and the web-app was up but then whenver we tried to access the Site Collection we would get FileNotFoundExceptions or the DirectoryNotFoundException. Details of the Message here:

File Not Found. at Microsoft.SharePoint.Library.SPRequestInternalClass.OpenWeb(String bstrUrl, String& pbstrServerRelativeUrl, String& pbstrTitle, String& pbstrDescription, Guid& pguidID, String& pbstrRequestAccessEmail, UInt32& pwebVersion, Guid& pguidScopeId, UInt32& pnAuthorID, UInt32& pnLanguage, UInt32& pnLocale, UInt16& pnTimeZone, Boolean& bTime24, Int16& pnCollation, UInt32& pnCollationLCID, Int16& pnCalendarType, Int16& pnAdjustHijriDays, Int16& pnAltCalendarType, Boolean& pbShowWeeks, Int16& pnFirstWeekOfYear, UInt32& pnFirstDayOfWeek, Int16& pnWorkDays, Int16& pnWorkDayStartHour, Int16& pnWorkDayEndHour, Int16& pnMeetingCount, Int32& plFlags, Boolean& bConnectedToPortal, String& pbstrPortalUrl, String& pbstrPortalName, Int32& plWebTemplateId, Int16& pnProvisionConfig, String& pbstrDefaultTheme, String& pbstrDefaultThemeCSSUrl, String& pbstrAlternateCSSUrl, String& pbstrCustomizedCssFileList, String& pbstrCustomJSUrl, String& pbstrAlternateHeaderUrl, String& pbstrMasterUrl, String& pbstrCustomMasterUrl, String& pbstrSiteLogoUrl, String& pbstrSiteLogoDescription, Object& pvarUser, Boolean& pvarIsAuditor, UInt64& ppermMask, Boolean& bUserIsSiteAdmin, Boolean& bHasUniquePerm, Guid& pguidUserInfoListID, Guid& pguidUniqueNavParent, Int32& plSiteFlags, DateTime& pdtLastContentChange, DateTime& pdtLastSecurityChange, String& pbstrWelcomePage)

 OR

System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\Usage
Analysis Logs'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path,
DirectorySecurity dirSecurity)
at System.IO.DirectoryInfo.Create(DirectorySecurity directorySecurity)
at
Microsoft.SharePoint.Administration.SPProvisioningAssistant.CreateDirectory(Director
yInfo di, Boolean secureAdminAccess)
at Microsoft.SharePoint.Administration.SPServer.CreateDirectory(String path,
Boolean secureAdminAccess)
at Microsoft.SharePoint.Administration.SPServer.CreateDirectory(String path)
at
Microsoft.SharePoint.Administration.SPUsageSettings.EnsureLogFileDirectories(SPFarm
farm)
at Microsoft.SharePoint.Administration.SPWebApplication.Provision()
at Microsoft.SharePoint.Administration.SPWebServiceInstance.Provision()
at Microsoft.SharePoint.Administration.SPFarm.Join()
at
Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.CreateOrConnec
tConfigDb()
at Microsoft.SharePoint.PostSetupConfiguration.ConfigurationDatabaseTask.Run()
at Microsoft.SharePoint.PostSetupConfiguration.TaskThread.ExecuteTask()

To resolve this error we tried following things:

1.We removed and added the same contentdb (restored the backup), but you i.e. basically we tried removing the original contentdb, and then re-added it n the web-app level using the Central Admin=>Application Management=>Content Databases. That also didnt help.

2. Tried accessing /_layouts/viewlsts.aspx work. That also threw the same error.

3. Tried accessing the/_layouts/settings.aspx work. That also threw the same error.

4. Checked all the solution files and they were also deployed properly and all artifacts were present on the file system.

Then after carefully looking at the error file not found appeared a file system error rather than a contentdb missing file error, so as Suggested by my colleague Andres Montenergo we checked if:

 

- There is a missing site definition or file, you might want to try running process monitor (procmon) while the problem happens and look for 'file not found' errors (filter the w3wp.exe process name).

- The contentdb is corrupt. Using SQL Analyzer, try to see how the tables looks like (for instance if you see data in alldocs, etc).

- The configdb has a reference (an id) to an old site collection but the same path.

 

And Finally it turned out that the GLOBAL.asax was missing and our site collection used some of the session used in that file, after fixing the Global.asax file our site collection was back up.

Hope this helps someone in case if you see any error like DirectoryNotFoundException or FileNotFound. Also A Big Thank you to Andres Montenegro as he sparked the idea to check the file system artifacts again.