Windows Server AppFabric How-To: Adding multiple persistence stores to an AppFabric installation
Yesterday someone contacted me in regards to adding a secondary persistence store to their AppFabric installation – they were trying to configure the environment so that workflow service A persists its instances to Store A, while workflow service B persists to Store B. Simple enough, right? Well, I realized that there was no documentation on how exactly to achieve this configuration. So, here you go…
Manual registration of additional persistence stores
The first step of course, is to physically create and initialize a persistence database. Start the Configure AppFabric wizard, and select next to go to the Hosting Services config page. Tick the Set persistence configuration checkbox, select sqlStoreProvider as the Persistence provider, and click the Configure button:
In the Persistence Store Configuration window, tick the Initialize persistence store checkbox, specify the Server and Database names for the new persistence database, and then click OK:
Note: Do no tick the "Register AppFabric persistence store in root web.config" checkbox – we will add the required entries manually.
Now, if you open your root web.config, towards the end of the file you will find a section that "declares" the instance stores that AppFabric knows about. Here's an extract with the default config from my machine:
To declare a new persistence store, you should create another <add> element under <instanceStores> . Note that you will also need to define a corresponding connection string under the <connectionStrings> element a bit further down in the file. Your modified web.config file should look similar to:
Save the file. You now have a second persistence store that you can use for your workflow services.
Scripted Version
To perform the above tasks you can also use the AppFabric PowerShell cmdlets as follows:
Start a PowerShell cmd window with elevated privileges and import the AppFabric management module:
import-module ApplicationServer
Create and initialize a new persistence database using the Initialize-ASPersistenceSqlDatabase cmdlet:
Initialize-ASPersistenceSqlDatabase –Database "NewDB" –Server "NewDBServer\SQLEXPRESS" –Admins "Domain\AppServerAdmins" –Readers "DOMAIN\AppServerReaders" –Users "DOMAIN\AppServerUsers"
Note: The user groups you specify for the –Admins, –Readers, and –Users parameters will be specific to your environment
Use the Add-ASAppSqlInstanceStore cmdlet to register the persistence store in the root web.config file:
Add-ASAppSqlInstanceStore -Name secondarySqlPersistenceStore -ConnectionString "Data Source=sqlServerName2\SQLEXPRESS;Initial Catalog=NewDB;Integrated Security=True" –root
Here is the copy/paste-ready script:
import-module ApplicationServer
Initialize-ASPersistenceSqlDatabase –Database "NewDB" –Server "NewDBServer\SQLEXPRESS" –Admins "Domain\AppServerAdmins" –Readers "DOMAIN\AppServerReaders" –Users "DOMAIN\AppServerUsers"
add-ASAppSqlInstanceStore -Name secondarySqlPersistenceStore -ConnectionString "Data Source=sqlServerName2\SQLEXPRESS;Initial Catalog=NewDB;Integrated Security=True" –root
Final notes
The above steps register the new persistence store at the root level (through the root web.config file). This means that the new store will be available for use by all AppFabric applications running on machine. You may also choose to add a persistence store at a specific scope in the IIS application hierarchy. For the scripted version, the only difference will be in the parameters passed to the cmdlet in step 3 – the full list of parameters for the cmdlet is available on its documentation page.
Comments
- Anonymous
January 27, 2011
Hi Emil,I just tried this out because I wanted to start 2 workflow projects and wanted for second one to use other persistence store. I did all steps, created additonal database with configuration tool of appfabric. This went fine. Then I added additional connection string and instance store in root web.config. I restarted the server and tried to configure persistence for selected site. I found Sql server store but also got following exception:"The connection string XY used by the current store cannot be found. Workflow instances will not persist. Please select another instance."But the connection string XY for sure exists in root web config and is used in additional instance store. Did I update some wrong web.config? I found web config under: C:WindowsMicrosoft.NETFramework64v4.0.30319Config. As you see I have 64 virtual machine but as I saw this config will be used by appfabric.My update look likes this:<connectionStrings> <add connectionString="Data Source=.SQLEXPRESS;Initial Catalog=XYCatalog;Integrated Security=True;Persist Security=True" name="XY" /> </connectionStrings><microsoft.applicationServer>
<instanceStores> <add name="XYSqlPersistenceStore" provider="SqlPersistenceStoreProvider" connectionStringName="XY" /> </instanceStores><persistence> <instanceStoreProviders lockItem="true"> <add name="SqlPersistenceStoreProvider" storeProvider="Microsoft.ApplicationServer.StoreProvider.Sql.SqlWorkflowInstanceStoreProvider, Microsoft.ApplicationServer.StoreProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" storeControlProvider="Microsoft.ApplicationServer.StoreManagement.Sql.Control.SqlInstanceControlProvider, Microsoft.ApplicationServer.StoreManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" storeQueryProvider="Microsoft.ApplicationServer.StoreManagement.Sql.Query.SqlInstanceQueryProvider, Microsoft.ApplicationServer.StoreManagement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </instanceStoreProviders> <workflowManagement> <workflowManagementServiceInstances lockItem="true"> <workflowManagementServiceInstance name=""> </workflowManagementServiceInstance> </workflowManagementServiceInstances> </workflowManagement>
I would appriciate any help!Kr,Dejan</persistence> <hosting> <serviceManagement endpointConfiguration="ServiceManagementNetPipeEndpoint" enabled="true" authorizedWindowsGroup="AS_Administrators" /> </hosting></microsoft.applicationServer>