我正在研究一个ChatBot项目,该项目需要从Azure托管的SQL数据库中的表中查询,并将结果用作对机器人的答复。
我正在使用Azure Web App Bot中的基本bot模板。 Bot无需连接数据库就可以独立运行。数据库没有问题,我能够在MVC Web应用程序中使用EF DB first方法从同一数据库中查询。
但是在项目中,如果我使用相同的方法,则会出现错误: 连接ECONNREFUSED
在这种情况下,机器人无法工作或无法连接。 任何人都可以帮助我解决此问题,或者是否可以获取详细的文档来开发可以查询并与Azure SQL数据库进行交互的漫游器。
预先感谢:)
答案 0 :(得分:1)
Here,您将找到一个简单的示例,该示例说明如何从Bot连接到Azure SQL数据库并插入数据。
要使用Azure SQL,请在Global.asax中配置Autofac依赖项注入。特别是以下是配置Azure Sql Storage注入的代码段:
var store = new SqlBotDataStore(ConfigurationManager.ConnectionStrings["BotDataContextConnectionString"].ConnectionString);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
Azure SQL数据库的连接字符串应该在web.config中:
<connectionStrings>
<add name="BotDataContextConnectionString"
providerName="System.Data.SqlClient"
connectionString="Server=tcp:[YourDatabaseServerName].database.windows.net,1433;Initial Catalog=[YourDatabaseName];Persist Security Info=False;User ID=[YourDatabaseUserId];Password=[YourDatabaseUserPassword];MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" />
</connectionStrings>