locked
The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. RRS feed

  • Question

  • User448619955 posted

    I'm using .Net core 2.0 and after running my app I get this issue:

    The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

    The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    
    
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <connectionStrings>
    
        <add name="InstayabContext"
             connectionString="Server=.;Database=InstaYab;User Id=blahblah; Password=blahblah;"
             providerName="System.Data.SqlClient" />
    
      </connectionStrings>
    
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="mssqllocaldb" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
    </configuration>
     var _cmd = new Commands();
     _cmd.commentLog(currentUser, fullName, mediaId, pk, userName, description + "/" + text, code);
    private readonly myDbContext _db = new myDbContext();
    
    public void commentLog(string CurrentUser,string FullName, string MediaId, long Pk, string Username,string Description,string Code)
            {
    
                var comment = new Comment
                {
                   
                    CreatedDate = DateTime.Now,
                    CurrentUser = CurrentUser,
                    FullName = FullName,
                    MediaId = MediaId,
                    Pk = Pk,
                    Username = Username,
                    Description=Description,
                    Code=Code
                };
                _db.Comments.Add(comment);
                _db.SaveChanges();
    
            }

    Saturday, May 18, 2019 6:14 PM

All replies

  • User1120430333 posted

    How is it that you have an app.config file? What kind of program is trying to use EF? Did you try to use the EF Core scaffolding through Nuget?

    Saturday, May 18, 2019 7:17 PM
  • User448619955 posted

    It's a console app (.NET Core) , another project in my solution is a class library in which , there are classes and models (EF), I referenced my class library into console app(.NET Core) and in app.config I added above codes.

    If I run my console app with .NET Framework everything works fine, but I want to use Bot Framework Emulator and I think it should be .NET Core application.

    Saturday, May 18, 2019 7:31 PM
  • User1120430333 posted

    [quote user

    ="vahid.ch"]

    It's a console app (.NET Core) , another project in my solution is a class library in which , there are classes and models (EF), I referenced my class library into console app(.NET Core) and in app.config I added above codes.

    If I run my console app with .NET Framework everything works fine, but I want to use Bot Framework Emulator and I think it should be .NET Core application.

    I don't know how it works for a Core solution as to where it expects to find the root.config/runtime config file or even if there is such a file that exist in Core that .NET Core even looks for at runtime on its own, like non Core .NET solutions do.. If the Bot program is not a Core solution or this classlib is not a Core classlib project, then things may be suspect in getting things to work.  

    All I can suggest is look at the thread,

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/64aa3ae1-b82e-4b79-be45-f193e1d97876/how-do-i-access-class-propertysettings-in-net-core?forum=csharpgeneral

    IMHO, what you are doing in not viable. 

    Saturday, May 18, 2019 9:46 PM