Я создал триггер HTTP и хочу вставить данные в azure - SQL с помощью приложения-функции. Я не могу правильно добавить пространства имен и ссылки в функции -app, пожалуйста, расскажите мне об этом, если у вас есть какие-либо примеры, пожалуйста, поделитесь
public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
log.LogInformation($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
var successful = true;
try
{
var cnnString = ConfigurationManager.ConnectionStrings["sqldb_connection"].ConnectionString;
using (SqlConnection connection = new SqlConnection(cnnString))
{
// var rLog = await req.Content.ReadAsAsync();
string query = "insert into [dbo].[EmployeeDetails](EmpName,EmpSal,EmpLocation) values(@empname,@empsal,@location)";
using (SqlCommand cmd = new SqlCommand(query, connection))
{
cmd.Parameters.AddWithValue("@empname", "Abhi");
cmd.Parameters.AddWithValue("@empsal", "150000");
cmd.Parameters.AddWithValue("@location", "HYderabad");
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
}
}
}
catch
{
successful = false;
}
return !successful
? req.CreateResponse(HttpStatusCode.BadRequest, "Unable to process your request!")
: req.CreateResponse(HttpStatusCode.OK, "Data saved successfully!");
}
public class EmployeeDetails
{
public int Id { get; set; }
public string EmpName { get; set; }
public string Empsal{get;set;}
public string EmpLocation{get;set;}
}
Ошибка, с которой я столкнулся
2020-07-10T07:39:05.906 [Error] Function compilation error
Microsoft.CodeAnalysis.Scripting.CompilationErrorException : Script
compilation failed. at async Microsoft.Azure.WebJobs.Script.Description.DotNetFunctionInvoker.CreateFunctionTarget(CancellationToken
cancellationToken) at
D:\a\1\s\src\WebJobs.Script\Description\DotNet\DotNetFunctionInvoker.cs
: 322 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
async
Microsoft.Azure.WebJobs.Script.Description.FunctionLoader`1.GetFunctionTargetAsync[T](Int32
attemptCount) at
D:\a\1\s\src\WebJobs.Script\Description\FunctionLoader.cs : 55 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2020-07-10T07:39:05.964 [Error] run.csx(7,8): error CS0246: The type
or namespace name 'Dapper' could not be found (are you missing a
using directive or an assembly reference?) 2020-07-10T07:39:06.017
[Error] run.csx(9,26): error CS0246: The type or namespace name
'IActionResult' could not be found (are you missing a using
directive or an assembly reference?) 2020-07-10T07:39:06.110
[Error] run.csx(11,86): error CS1061: 'HttpRequest' does not
contain a definition for 'RequestUri' and no accessible extension
method 'RequestUri' accepting a first argument of type
'HttpRequest' could be found (are you missing a using directive
or an assembly reference?)
2020-07-10T07:39:06.191 [Error] run.csx(39,24): error CS1501: No overload for method 'CreateResponse' takes 2 arguments
2020-07-10T07:39:06.402 [Error] run.csx(40,24): error CS1501: No
overload for method 'CreateResponse' takes 2 arguments
2020-07-10T07:39:06.441 [Warning] run.csx(9,41): warning CS1998:
This async method lacks 'await' operators and will run
synchronously. Consider using the 'await' operator to await
non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound
work on a background thread. 2020-07-10T07:39:06.493 [Error]
Executed 'Functions.HttpTrigger1' (Failed,
Id=5c5a88b6-c8ec-42e7-a6e4-1dc27e6f41f2) Script compilation
failed.
Project. json -file
"frameworks": {
"net46":{
"dependencies": {
"Dapper": "1.42.0",
"System.Data.SqlClient":"4.1.0",
"Microsoft.WindowsAzure.ConfigurationManager":"3.2.1"
}
}
}
}