Azure function app with SQL Trigger not working after deployment
Initially I also got the same issue. but, after adding the SQL Connection String in Environmental variables section worked as expected. Make sure key is same in both local and portal. check below:
Settings>>Environmental variables>>Connection strings

Function code:
app = func.FunctionApp()
@app.function_name(name="GetProducts")
@app.route(route="getproducts/{cost}")
@app.sql_input(arg_name="products",
command_text="SELECT * FROM Products WHERE Cost = @Cost",
command_type="Text",
parameters="@Cost={cost}",
connection_string_setting="SqlConnectionString")
def get_products(req: func.HttpRequest, products: func.SqlRowList) -> func.HttpResponse:
rows = list(map(lambda r: json.loads(r.to_json()), products))
return func.HttpResponse(
json.dumps(rows),
status_code=200,
mimetype="application/json"
)
@app.function_name(name="AddProduct")
@app.route(route="addproduct")
@app.sql_output(arg_name="product",
command_text="[dbo].[Products]",
connection_string_setting="SqlConnectionString")
def add_product(req: func.HttpRequest, product: func.Out[func.SqlRow]) -> func.HttpResponse:
body = json.loads(req.get_body())
row = func.SqlRow.from_dict(body)
product.set(row)
return func.HttpResponse(
body=req.get_body(),
status_code=201,
mimetype="application/json"
)
@app.function_name(name="ProductsTrigger")
@app.sql_trigger(arg_name="products",
table_name="Products",
connection_string_setting="SqlConnectionString")
def products_trigger(products: str) -> None:
logging.info("SQL Changes: %s", json.loads(products))
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
"SqlConnectionString": "Your SQL-Connection-string",
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
}
}
The data which i stored in my database below:

The Function worked fine in local.

The function deployed successfully into azure.

Output:
