2013-02-25 17 views
60

tôi sử dụng Entity Framework Code First,Chuỗi kết nối 'MyConnection' trong tập tin cấu hình của ứng dụng không chứa các thuộc tính providerName yêu cầu"

chuỗi kết nối của tôi là trong một tập tin cấu hình:

<connectionStrings> 
    <clear/> 
    <add name="ApplicationServices" connectionString="Data Source=PC-X;Initial Catalog=MYdb;Integrated Security=True"/> 
    </connectionStrings> 

Khi tôi cố gắng để truy cập dữ liệu (thứ gì đó cần tạo DB) rơi xuống với lỗi sau:

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

Điều gì a m tôi mất tích?

Trả lời

133

Bạn đang thiếu những đoạn mã sau đây sau khi thuộc tính connectionString (giả định rằng bạn đang sử dụng SQL):

providerName="System.Data.SqlClient"

+14

Nếu sử dụng khung pháp nhân: 'providerName =" System.Data.EntityClient "' – Dr1Ku

+13

SqlClient cũng hoạt động cho Khung thực thể. – IronMan84

+1

Ok, rất tốt để biết, cảm ơn bạn đã đứng đầu! – Dr1Ku

5

Đôi khi trong tương lai. mã hoàn chỉnh

<add name="YouContext" connectionString="Integrated Security=True;Persist Security Info=False;Initial Catalog=YourDatabaseName;Data Source=YourPCName;" providerName="System.Data.SqlClient"/> 
Các vấn đề liên quan