mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
24 lines
1021 B
C#
24 lines
1021 B
C#
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 };
|
|
}
|
|
} |