Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

.net - Entity Framework: "ProviderName" in connection string required- all of the sudden?

We've been using Entity framework in a production environment for many months now, and just yesterday started to get errors on some machines when querying the database using our subclass of DbContext:

"The connection string 'MyConnectionString' in the application's configuration file does not contain the required providerName attribute"

Our problem is easily solved: I adding the "providerName="System.Data.SqlClient" to the connection string in the config files on all deployed servers and workstations.

However, the mystery remains: according to the documentation:

The providerName attribute is optional, and the default is "System.Data.SqlClient".

Even more mysterious is why this started happening suddenly, and apparently only on some machines. I am not aware of any recent changes in EF or .NET versions, any SQL Server version or provider changes, or anything. But I realize there has to be something I've overlooked.

.NET 4.5 EF 5.0

Anyone have any hints or insights?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Certain driver combinations will cause the machine to be in a state where it is ambiguous which driver it should use, so it requires an explicit provider name.

It was probably some other separate application or driver install, or automatic Windows Update that ran.

Being explicit with the provider name doesn't hurt anything though. You should be fine adding it; it's only a few extra characters in your connection string. It won't ever need to change in the future or anything.

Your updated declaration should read:

<connectionStrings>
  <add
    name="MyConnectionStringName"
    connectionString="Connection string goes here"
    providerName="System.Data.SqlClient" />
</connectionStrings>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...