【发布时间】:2018-06-21 23:37:44
【问题描述】:
我正在使用 Nuget Microsoft.Bot.Builder.Azure 包扩展来存储我的机器人的状态。 BotBuilder 3.14.0、Bot.Builder.Azure 3.2.5。
到目前为止,我一直在使用 Azure 表存储成功使用 TableBotDataStore。在开始对话时,我可以立即检查表格并查看其中创建的相关行。
我尝试使用 SqlBotDataStore,运行脚本在我的 (Azure) SQL Server DB 中创建表。我按照sample code 注册了它,但在重新部署时我发现,虽然没有抛出错误,但在 SqlBotDataEntities 表中没有创建任何条目,而是将 state.botframework.com 作为请求依赖项的一部分调用。
var sqlStore = new SqlBotDataStore(ConfigurationManager.
ConnectionStrings["SqlBotStorage"].ConnectionString);
builder.Register(c => sqlStore)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
已取代(工作)
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();
我知道连接字符串是 kosher,因为我尝试了一个虚拟操作方法的测试:
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));
添加一行就好了。
我还缺少什么?相关连接字符串存储在 Azure 应用程序设置中,作为“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;
【问题讨论】:
-
不是存储账户,是数据库连接字符串。这是正确的,正如我上面所说,我尝试显式创建 SqlBotDataStore 的实例,并且它正确写入数据库。
-
您是否尝试过在 SqlBotDataStore 实现中包含 CachingBotDataStore 注册?我认为 AzureModule 是必需的,如果您不使用 CachingBotDataStore(正如您在下面的回答中所述)
-
我没有费心在 Eric 上添加 CachingBotDataStore,因为在示例代码 sn-ps 中似乎不需要它,而且我当前的 bot 使用量并不大,以至于不能保证任何还担心缓存机制——而且,最重要的是,我仍然担心 CachingBotDataStore 在 3.15 死亡问题中可能扮演的角色:github.com/Microsoft/BotBuilder/issues/4477
-
顺便说一句,感谢您的澄清。使用 CachingBotDataStore 意味着您不需要注册 AzureModule。这将是在文档中突出显示的一个方便的方法。
-
(死亡问题 + 1) ...我想它终于解决了
标签: c# azure azure-sql-database botframework azure-bot-service