oflahero
oflahero

Reputation: 1330

Using SqlBotDataStore for bot state falls back instead to state.botframework.com

I'm using the Nuget Microsoft.Bot.Builder.Azure package extensions to store my bot's state. BotBuilder 3.14.0, Bot.Builder.Azure 3.2.5.

I've been successfully using TableBotDataStore up until now, using Azure table storage. On starting a conversation, I can immediately inspect the table and see relevant rows created in it.

I tried using SqlBotDataStore, having run the script to create the table in my (Azure) SQL Server DB. I registered it as per the sample code, but on redeployment I find that, although no errors are thrown, no entries are created in the SqlBotDataEntities table, and instead state.botframework.com is being called as part of the request dependencies.

var sqlStore = new SqlBotDataStore(ConfigurationManager.
    ConnectionStrings["SqlBotStorage"].ConnectionString);

builder.Register(c => sqlStore)
                    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                    .AsSelf()
                    .SingleInstance();

has replaced the (working)

var azureTableStore = new TableBotDataStore( 
    ConfigurationManager.ConnectionStrings["TableStorageCS"].ConnectionString,
    sBotStorageTableName);

builder.Register(c => azureTableStore)
                    .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                    .AsSelf()
                    .SingleInstance();

builder.Register(c => new CachingBotDataStore(azureTableStore,
                    CachingBotDataStoreConsistencyPolicy
                    .ETagBasedConsistency))
                    .As<IBotDataStore<BotData>>()
                    .AsSelf()
                    .InstancePerLifetimeScope();

I know the connection string is kosher, as I tried a test in a dummy action method:

IBotDataStore<BotData> sqlds = new SqlBotDataStore( 
    ConfigurationManager.ConnectionStrings["SqlBotStorage"].ConnectionString);

var key = new Address("botidhere", "effbee", "uid1", "c1", "x.com");
var bd = new BotData(data: new Dialogs.SimpleResponseDialog("message here"));
await sqlds.SaveAsync(key, BotStoreType.BotUserData, bd, default(CancellationToken));

and that adds a row just fine.

What else am I missing? The relevant connection string is stored in Azure application settings, as a connection string of type 'SQLAzure':

Server=tcp:xxxx.database.windows.net;Initial Catalog=xxxx;Persist Security Info=False;User ID=xxxx;Password=xxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

Upvotes: 1

Views: 256

Answers (1)

oflahero
oflahero

Reputation: 1330

I appear* to have fixed it - I was missing the AzureModule registration line:

builder.RegisterModule(new AzureModule(System.Reflection.Assembly.GetExecutingAssembly()));

Here's the thing though - this wasn't needed for using TableBotDataStore. Only SqlBotDataStore.

Another thing: adding the line fixed the issue immediately in an Azure deployment slot with a debug build, system.debug=true. However, deploying to the main webapp (non-slot) with a release build, system.debug=false caused the app to be unable to start. '503 Service Unavailable'. No logs. Reverting immediately to table storage and all was well again.

I'm currently try..catching the above line, but I can't see an exception thrown, yet it has started working now. One to keep an eye on!

*with caveats above...

Upvotes: 1

Related Questions