An error occurred while getting provider informati

2019-04-22 20:26发布

问题:

Getting the error:

System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string.
Check the inner exceptions for details and ensure that the connection string is correct.
---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.
---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

I get the same error when trying to do an Add-Migration

Here is my connection string, I need to access my local SQL server and NOT SQLEXPRESS.

  <connectionStrings>
    <add name="ReaderInsightDbContext" 
         connectionString="data source=localhost\MSSQLSERVER;
                         initial catalog=ReaderInsight;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
  </connectionStrings>

My DB is located:

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA

So my instance is MSSQLSERVER. Not sure what is going on. It first worked just fine, but after I changed my code to use the UOW pattern, this is happening. I also upgraded from EF 4.3 to EF5. Same issue.

I tried many variations of the data source in the connection string, none work, here are some examples:

  • localhost\MSSQLSERVER
  • .\MSSQLSERVER
  • //localhost\MSSQLSERVER
  • (local)\MSSQLSERVER
  • 127.0.0.1\MSSQLSERVER

If I do .\SQLEXPRESS it works.

回答1:

Managed to get it resolved.

Bottom line manually deleting the migration files causes issues.

Made sure my connection string looks like so:

  <connectionStrings>
    <add name="ReaderInsightDbContext" 
     connectionString=
     "Data Source=(local);Initial Catalog=ReaderInsight;Integrated Security=True"
     providerName="System.Data.SqlClient" />
  </connectionStrings>

Performed an Update-Database -TargetMigration:$InitialDatabase which did not work as it said there is still pending changes.

So I performed

System.Data.Entity.Database.SetInitializer(     
  new System.Data
            .Entity
            .DropCreateDatabaseIfModelChanges<ReaderInsightDbContext>()); 

in the global.asax file.

Commented it out, so it wont run again. I then did a Add-Migration Init and it recreated the script for the entire DB and when I ran Update-Database worked like a charm.



回答2:

I got it solved by setting the start up project in my solution to the entity dll project ( having app.config file ). I did set the "Default project" in Package Manager Console window to the correct entity dll project but that did't work. For details

Entity Framework 6 with SQL Server 2012 gives System.Data.Entity.Core.ProviderIncompatibleException system-data-entity-core-providerin



回答3:

See this post:

MVC3 Music Store Tutorial Connection String issue

Looks like you are missing the MARS setting.



回答4:

I had this problem when I changed my password that SQL Server won't start. Check that :)



回答5:

Check that, The SQL Server you are using in the connection string is started or not.



回答6:

I had the same problem the other day. The reason was my MSSQL server version. I tried to use VS2010 and SQL SERVER 2008 and then it didn't work. It worked fine with SQL Express which comes with VS2010 (and it wasn't started) but not with SQL SERVER.



回答7:

I used this with VS 2010 and it worked:

  1. Added User Instance=true
  2. Used the data source .\SQLEXPRESS