jonwagner/Insight.Database

Cannot derive parameters for the stored procedure X. Have you loaded the provider that supports SqlCommand?

jesserizzo opened this issue · 3 comments

Describe the bug

Created a new Azure Function project in an existing sln. Insight works fine in the API project, but fails when called from the Function App with the message
Cannot derive parameters for the stored procedure GetEmployerPaidStatus. Have you loaded the provider that supports SqlCommand?

Steps to reproduce

Create a new timer triggered Azure function (func init and func new commands)
Run the following code

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using System.Data.Common;
using Microsoft.Data.SqlClient;
using Insight.Database;

namespace temp
{
    public class Test
    {
        [FunctionName("Test")]
        public void Run([TimerTrigger("0 */1 * * * *", RunOnStartup = true)] TimerInfo myTimer, ILogger log)
        {
            SqlInsightDbProvider.RegisterProvider();
            DbConnection connection = new SqlConnection("valid connection string");
            TestRepository repository = connection.As<TestRepository>();
            repository.StoredProcedureName();
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }

    public interface TestRepository
    {
        public bool StoredProcedureName();
    }
}

Expected behavior

Insight should be able to call the stored procedure

  • Dotnet version: [Dotnet 6]
  • Database: [SQL Server]
  • Library version: [6.3.10]

Ok this is fixed now, I needed to call
Insight.Database.Providers.MsSqlClient.SqlInsightDbProvider.RegisterProvider();

Ok this is fixed now, I needed to call Insight.Database.Providers.MsSqlClient.SqlInsightDbProvider.RegisterProvider();

Right, but where, exactly?

Jaxelr commented

Anywhere before it interacts with the Db should be fine. See this wiki