Entity Framework - Expecting non-empty string for 'providerInvariantName' parameter

前端 未结 2 1693
说谎
说谎 2021-02-07 07:18

Ok, this may not be related to EF. I am trying to use the code-first feature and following is what I wrote:-

var modelBuilder = new ModelBuilder();
            v         


        
相关标签:
2条回答
  • 2021-02-07 08:06

    You should add the System.Data.SqlClient as the value to a new attribute named "ProviderName". Just like below :-

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <connectionStrings>
        <add name="AddressBook" providerName="System.Data.SqlClient"  connectionString="Data Source=MyMachine;Initial Catalog=AddressBook;Integrated Security=True;MultipleActiveResultSets=True;"/>
        </connectionStrings>
    </configuration>
    
    0 讨论(0)
  • 2021-02-07 08:16

    I had the same error when I uploaded my website to the production server. My connection string had the providerName property set. The cuase of the problem was a connection string in machine.config named LocalSqlServer and a role provider that has used that connection string:

    <roleManager>
       <providers>
       <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       ....
    

    So all I had to do was clearing connection strings and role providers before registering mine:

      <connectionStrings>
        <clear/>
        <add name="DbEntities" connectionString="..." providerName="System.Data.SqlClient" />
      </connectionStrings>
      ...
      <roleManager defaultProvider="DefaultRoleProvider" enabled="true">
        <providers>
          <clear/>
          <add name="DefaultRoleProvider" ... />
        </providers>
      </roleManager>
    
    0 讨论(0)
提交回复
热议问题