使用.NET在mySQL中保存bot状态数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用.NET在mySQL中保存bot状态数据相关的知识,希望对你有一定的参考价值。

由于Bot State服务很快就会退役,我想将我的bot状态信息存储在我的本地mysql数据库中。

我尝试使用mySQL连接字符串在Global.asax中实例化SqlBotDataStore客户端,但我认为由于尚未创建SqlBotDataEntities表,我遗漏了一些东西。

请就此提出建议。谢谢!

protected void Application_Start(object sender, EventArgs e)

    
        var config = GlobalConfiguration.Configuration;

        Conversation.UpdateContainer(
            builder =>
                
                    builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly()));

                    var store = new SqlBotDataStore(ConfigurationManager.ConnectionStrings["mySQL_ConnectionString"].ConnectionString);

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


                    // Register your Web API controllers.
                    builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
                    builder.RegisterWebApiFilterProvider(config);

                );

        config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container);
    

    // WebApiConfig stuff
    GlobalConfiguration.Configure(config =>
    
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/controller/id",
            defaults: new  id = RouteParameter.Optional 
        );
    );

答案

SqlBotDataStorehttps://github.com/Microsoft/BotBuilder-Azure/是针对Azure SQL而不是MySQL而制作的。

您不能将它与MySQL数据库一起使用。

这个NuGet包有2个选项:

  • Azure表存储
  • CosmosDB

以上是关于使用.NET在mySQL中保存bot状态数据的主要内容,如果未能解决你的问题,请参考以下文章

如何将数据保存在 JSON 文件中,这样每次我的 Discord Bot 注销时数据都不会重置

Asp.Net将Session保存在数据库中

discord bot 不保存到 mongoDB

无法使用 JSON 将 jqxScheduler 状态存储到 MySQL

Azure Bot 脚本未保存

如何使用 Alamofire 将用户配置文件图像保存到 MYSQL 数据库,然后在以下屏幕上检索