I am following this guide to create a binding to update my database: https://learn.microsoft.com/da-dk/azure/azure-functions/functions-bindings-azure-sql-output?tabs=csharp
I feel like I have done everything the guide says, however I am still getting an error.
The error is:
[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 ..
The function code is the following:
[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();
}
This is my model:
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; }
}
My database:
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)
);
I purposley set the DB fields to NOT NULL so I could easily test the insert functions with just to values
ANY help is much appreciated.