我按照本指南创建一个绑定来更新我的数据库:https://learn.microsoft.com/da-dk/azure/azure-functions/functions-bindings-azure-sql-output?tabs=csharp
我觉得我已经完成了导游说的每一件事,但我还是犯了一个错误。
错误为:
[2022-03-10T20:39:31.466Z] Executed 'PostFileInformationByDeviceId' (Failed, Id=d0cecd1b-e54b-4716-9cfc-921bb6f458ac, Duration=701ms)
[2022-03-10T20:39:31.467Z] System.Private.CoreLib: Exception while executing function: PostFileInformationByDeviceId. Microsoft.Azure.WebJobs.Host: Error while handling parameter newItem after function returned:. Microsoft.Azure.WebJobs.Extensions.Sql: Encountered error(s) while parsing schema and object name: Incorrect syntax near ..
功能代码如下:
[FunctionName("PostFileInformationByDeviceId")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "postFile/{deviceId}")]
HttpRequest req, [Sql("dbo.File", ConnectionStringSetting = "SqlConnectionString")] out FileInformation newItem,
ILogger log)
{
newItem = new FileInformation
{
Hash = "hash",
DeviceId = "deviceid"
};
return new OkResult();
}
这是我的型号:
public class FileInformation
{
public string Hash { get; set; }
public string UserId { get; set; }
public string DeviceId { get; set; }
public int Timestamp { get; set; }
public string Filename { get; set; }
public int Filetype { get; set; }
}
我的数据库:
CREATE TABLE [dbo].[File] (
[Hash] VARCHAR (20) NOT NULL,
[Timestamp] INT NULL,
[DeviceId] NCHAR (10) NOT NULL,
[UserId] NCHAR (10) NULL,
[Filename] NCHAR (10) NULL,
[Filetype] INT NULL,
PRIMARY KEY CLUSTERED ([Hash] ASC)
);
我有意将DB字段设置为NOT NULL,这样我就可以很容易地用值测试插入函数
我们非常感谢您的帮助。
"文件";是T-SQL:中的保留字
https://learn.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql?view=sql-服务器-ver15
试着给你的桌子命名一些不是保留词的东西——";dbo。MyFile";,可能