mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Added example with Azure Function REST API
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
using System.Net;
|
||||
using System.Configuration;
|
||||
using Belgrade.SqlClient;
|
||||
using Belgrade.SqlClient.SqlDb;
|
||||
|
||||
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
|
||||
{
|
||||
log.Info("C# HTTP trigger function processed a request.");
|
||||
|
||||
try{
|
||||
string ConnectionString = ConfigurationManager.ConnectionStrings["azure-db-connection"].ConnectionString;
|
||||
|
||||
var httpStatus = HttpStatusCode.OK;
|
||||
string body =
|
||||
await (new QueryMapper(ConnectionString)
|
||||
.OnError(ex => { httpStatus = HttpStatusCode.InternalServerError; }))
|
||||
.GetStringAsync("select * from sys.objects for json path");
|
||||
return new HttpResponseMessage() { Content = new StringContent(body), StatusCode = httpStatus };
|
||||
|
||||
} catch (Exception ex) {
|
||||
log.Error($"C# Http trigger function exception: {ex.Message}");
|
||||
return new HttpResponseMessage() { Content = new StringContent(""), StatusCode = HttpStatusCode.InternalServerError };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user