[英]Executing Query via C# MVC API
我在處理某些代碼時遇到了麻煩,而且我似乎無法弄清楚。 我正在嘗試將一些數據發送到連接到我們的SQL Server的后端API,並執行我不希望有任何結果的查詢。 我遇到的問題是沒有將SQL命令發送到服務器,並且得到了“ 404-該文件不存在”。
這是請求的前面部分:
public async Task ExportNewLists (string pid, string list)
{
var endpointUrl = string.Concat(baseEndpoint, "ExportLists", "/", pid, "/", list);
AddAuthorization();
using (HttpResponseMessage response = await client.GetAsync(endpointUrl))
{
if (!response.IsSuccessStatusCode)
{
Response.StatusCode = (int)response.StatusCode;
var result = response.Content.ReadAsStringAsync().Result;
var message = JsonConvert.DeserializeObject<ResponseError>(result);
}
}
}
這是我嘗試調用的API函數:
[Route("api/Lists/ExportLists/{pid}/{list}")]
[HttpGet]
[ResponseType(typeof(void))]
private async Task<IHttpActionResult> ExportList(string pid, string list)
{
using (var connection = db.Database.Connection)
{
try
{
connection.Open();
var command = connection.CreateCommand();
command.Connection = connection;
command.CommandText = "EXEC LIST_EXPORT_SINGLE";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@PID");
command.Parameters["@PID"].Value = pid;
command.Parameters.Add("@LIST");
command.Parameters["@LIST"].Value = list;
await command.ExecuteNonQueryAsync();
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return Ok();
}
您已將ExportScrubList標記為私有。 您無法通過http調用標記為私人的操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.