Showing posts with label AppFabric. Show all posts
Showing posts with label AppFabric. Show all posts

Tuesday, 16 April 2013

Clearing Windows Server AppFabric databases


If you have been using Windows Service AppFabric, you would be aware of the two AppFabric databases. The AppFabric Monitoring database and AppFabric Persistence database. The Monitoring database stores events information while the persistence database store information about instance data and metadata.

It is often are requirement to clean up the database, especially if you deploying to a clean environment. The following MSBuild file will help do that.


    <UsingTask TaskFactory="PowershellTaskFactory" TaskName="ResetAppFabricDatabases" AssemblyFile="$(PowerShellAssemblyFile)">
        <ParameterGroup>
            <AppFabAdmins Required="true" ParameterType="System.String"/>
            <AppFabReaders Required="true" ParameterType="System.String"/>
            <AppFabUsers Required="true" ParameterType="System.String"/>
            <MonitoringDbName Required="true" ParameterType="System.String" />
            <MonitoringDbServer Required="true" ParameterType="System.String" />
            <PersistenceDbName Required="true" ParameterType="System.String" />
            <PersistenceDbServer Required="true" ParameterType="System.String" />
            <ConfirmPreference Required="true" ParameterType="System.String" />
        </ParameterGroup>
        <Task>
            <![CDATA[         
                            $executionPolicy = Get-ExecutionPolicy
                            Set-ExecutionPolicy Unrestricted                        
                Import-Module ApplicationServer
                $log.LogMessage([Microsoft.Build.Framework.MessageImportance]"Normal", "Removing persistance database {0} on sql instance {1}.", $PersistenceDbName, $PersistenceDbServer)
                Remove-ASPersistenceSqlDatabase -Force -Server $PersistenceDbServer -Database $PersistenceDbName            
            
                $log.LogMessage([Microsoft.Build.Framework.MessageImportance]"Normal", "Creating persistance database.")
                Initialize-ASPersistenceSqlDatabase -Admins $AppFabAdmins -Readers $AppFabReaders -Users $AppFabUsers -Database $PersistenceDbName -Server $PersistenceDbServer
            
                $log.LogMessage([Microsoft.Build.Framework.MessageImportance]"Normal", "Clearing Monitoring Database {0} on sql instance {1}.", $MonitoringDbName, $MonitoringDbServer)
                Clear-ASMonitoringSqlDatabase -Database $MonitoringDbName -Server $MonitoringDbServer                        
                        
                            Set-ExecutionPolicy $executionPolicy                        
                ]]>
        </Task>
    </UsingTask>


Just call the Target  "ResetAppFabricDatabases" from your project file as shown below.

Please note that you would need to have MSBuildExtensions pack installed on your machine to run this script.

    <Target Name="ClearDownAppFabric">
        <ResetAppFabricDatabases AppFabAdmins="$(Domain)\$(AppFabricAdministratorsGroup)"
                                 AppFabReaders="$(Domain)\$(AppFabricObserversGroup)"
                                 AppFabUsers="$(Domain)\$(AppFabricUsersGroup)"
                                 MonitoringDbName="$(APFMonitoringDatabaseName)"
                                 MonitoringDbServer="$(APFDatabaseServer)"
                                 PersistenceDbName="$(APFPersistenceDatabaseName)"
                                 PersistenceDbServer="$(APFDatabaseServer)"
                                 ConfirmPreference="None"/>
    </Target>

You can download the sample from here

Wednesday, 24 October 2012

IIS Deployment and Windows Server AppFabric services.


I had been getting the following error intermittently while deploying some IIS artifacts on a Windows 2008 server with Windows AppFabric installed on it

FileLoadException: The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

Since, all deployments to IIS result in modifications to the applicationHost.config file, it was obvious that the FileLoadException was raised for this file. Using the Unlocker utility, I found that the file was locked by the two AppFabric services i.e. "AppFabric Event Collection Service"  and "AppFabric Workflow Management Service".

The workaround is to stop the two services before you do any deployment on IIS and start them afterwards.

If you are not familiar with applicationHost.config file, this link is a good resource to understand the structure and use of this file.