如何将ms-botframework连接到Azure数据库 [英] how to connect ms-botframework to azure database
本文介绍了如何将ms-botframework连接到Azure数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将.Net应用程序BotFramework连接到数据库并将数据存储在MS SQL Azure中?
How to connect .Net application BotFramework to database and store data in MS SQL azure?
我想在db中使用存储过程并保存已发送和已接收的消息.
I want use stored procedure in db and save sent and recieved messages.
代码示例 如果我使用到localdb或本地服务器的连接字符串,则此代码有效.
Code Sample This code is work if I used connection string to localdb or local server
Webconfig
Webconfig
<connectionStrings>
<add name="[ConnStr]" connectionString="Data Source=[SiteURL].database.windows.net;Initial Catalog=[Name];Persist Security Info=True;User ID=[User];Password=[Password]" providerName="System.Data.SqlClient" />
</connectionStrings>
... MessagesController.cs
... MessagesController.cs
[BotAuthentication]
public class MessagesController : ApiController
{
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
LogMessage();
await connector.Conversations.ReplyToActivityAsync(reply);
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
...
private void LogMessage()
{
var context = new DataClasses1DataContext(ConfigurationManager.ConnectionStrings["[ConnStr]"].ConnectionString);
var newMessage = new Table1
{
Table101 = newID()
,
Table102 = DateTime.Now
,
Table103 = 0
,
Table104 = "Test"
,
Table105 = "Test2"
,
Table106 = "Test3"
,
Table107 = 0
,
Table108 = "Test4"
,
Table109 = 0
};
context.Table1.InsertOnSubmit(newMessage);
context.Table1.Context.SubmitChanges();
}
推荐答案
非常感谢,我没有找到解决问题的方法,而是重新创建了所有示例项目,它可以正常工作.
Thanks all, I dont find solution for my problem and recreate all sample project and it's work.
此问题中的示例代码有效
Sample code in this Questions it's work
我认为 查看全文