我有一个Azure Event hub智能电表的读数。我正在尝试使用将Azure Function仪表读数写入 Azure SQL DB。我在 Azure SQL DB 中创建了一个目标表和一个存储过程来解析 JSON 并将内容存储在表中。我已经成功测试了存储过程。
然而,当我从 Azure 函数调用它时,出现错误:“System.Data.SqlClient.TdsParser”的类型初始值设定项引发异常。出于测试目的,我尝试从 Azure 函数执行一个简单的 SQL select 语句,但这给出了相同的错误。我现在迷失了,因为我尝试了很多选择但没有运气。这是Azure功能代码:
#r "Microsoft.Azure.EventHubs"
using System;
using System.Text;
using System.Data;
using Microsoft.Azure.EventHubs;
using System.Data.SqlClient;
using System.Configuration;
using Dapper;
public static async Task Run(string events, ILogger log)
{
var exceptions = new List<Exception>();
try
{
if(String.IsNullOrWhiteSpace(events))
return;
try{
string ConnString = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_azure-db-connection-meterreadevents", EnvironmentVariableTarget.Process);
using(SqlConnection conn = new SqlConnection(ConnString))
{
conn.Execute("dbo.ImportEvents", new { Events = events }, commandType: CommandType.StoredProcedure); …Run Code Online (Sandbox Code Playgroud)