jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM
Other
856 stars 145 forks source link

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

Closed jesserizzo closed 2 years ago

jesserizzo commented 2 years ago

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

jesserizzo commented 2 years ago

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

nickpreston24 commented 8 months ago

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

Right, but where, exactly?

Jaxelr commented 8 months ago

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