我想在 microsoft bot 框架 c# 中有一个机器人,如果你发送名字,它会发回一个人最喜欢的颜色值。数据存储在 azure 上的数据库中。连接很好,问题是一旦我尝试实现任何读取器对象,它就会给出代码 500 错误。例子:用户:账单机器人:比尔最喜欢的颜色是红色!你想知道别人最喜欢的颜色吗?因此,该逻辑应采用 bill 的用户输入,将其用作 sql 语句中的输入参数,然后读取返回值并通过机器人返回给用户。我的 MessagesController.cs 类与机器人模板没有变化,我尝试将所有逻辑放在下面的 RootDialog.cs 中:using System;using System.Threading.Tasks;using Microsoft.Bot.Builder.Dialogs;using Microsoft.Bot.Connector;using System.Data.SqlClient;namespace ColourBot.Dialogs{[Serializable]public class RootDialog : IDialog<object>{ public Task StartAsync(IDialogContext context) { context.Wait(MessageReceivedAsync); return Task.CompletedTask; } private async Task MessageReceivedAsync(IDialogContext context, IAwaitable<object> result) { var activity = await result as Activity; string result10; var cb = new SqlConnectionStringBuilder(); cb.DataSource = "my_server.database.windows.net"; cb.UserID = "user_id"; cb.Password = "pass_word"; cb.InitialCatalog = "ColourDB"; using (var connection = new SqlConnection(cb.ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand("SELECT Colour FROM People Where Name=ed", connection); result10 = Submit_1_Tsql_SelectEmployees(connection); await context.PostAsync( $"The name you sent was {activity.Text}, their favourite colour is {result10}!"); context.Wait(MessageReceivedAsync); string Build_1_Tsql_SelectEmployees() { return $@"SELECT Colour FROM People Where Name={activity.Text};"; }
1 回答
- 1 回答
- 0 关注
- 136 浏览
添加回答
举报
0/150
提交
取消