2011-12-19 29 views
1

我使用Code First。一切正常(插入,更新,選擇)一切都經過測試。我嘗試使用Web服務時出現問題。我收到錯誤「System.Data.ProviderIncompatibleException:提供程序沒有返回ProviderManifestToken字符串」。看看內部異常,我收到了這條消息:「無法確定存儲版本;需要有效的存儲連接或版本提示。」在Web服務中使用Code First時出錯「System.Data.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串」。

Web服務代碼:

/// <summary> 
/// Summary description for UserServices 
/// </summary> 
[WebService(Namespace = "http://localhost:3955/WebServices/UserServices")] 
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
//[System.ComponentModel.ToolboxItem(false)] 
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService] 
public class UserServices : System.Web.Services.WebService 
{ 

    [WebMethod] 
    public bool LoginControlPanelUser(string user, string password) 
    { 
     if(Membership.ValidateUser(user, password)) 
     { 
      return DbUsersDAO.HasAuthenticationType(user, password); 
     } 
     return false; 
    } 
} 

的DAO代碼:

public static bool HasAuthenticationType(string user, string authenticationTypeCode) 
    { 
     try 
     { 
      using (VirtusCloudCoreContext ctx = new VirtusCloudCoreContext()) 
      { 
       DBUser User = ctx.DBUsers.SingleOrDefault(u => u.Login.Equals(user) && u.Active.Equals(true)); 
       if (User != null) 
       { 
         return DBAuthenticationTypesDAO.GetById(User.DBAuthenticationTypeId).Name.Equals("Admin"); 
       } 
      } 
      return false; 

     } 
     catch (Exception ex) 
     { 
      ErrorsHelper.InsertError(ex); 
      throw ex; 
     } 
    } 

上下文類:

public VirtusCloudCoreContext() 
    { 
     Database.SetInitializer<VirtusCloudCoreContext>(new VirtusCloudCoreContextInitializer()); 
     this.Database.Connection.ConnectionString = "Data Source=localhost\SQLEXPRESS;Database=DatabaseName;User Id=******;Password=*******;" ; 

    } 

我得到的異常當我嘗試獲取用戶。 ... 有任何想法嗎?

回答

3

這個錯誤通常發生在連接字符串錯誤的時候,但我認爲在你的情況下,這是因爲你試圖手動設置連接字符串。

嘗試使你的背景下從的DbContext繼承,並採取在你的構造一個連接字符串,它貫穿於底座的構造,就像這樣:

public class VirtualCloudCoreContext : DbContext { 
    public VirtualCloudCoreContext(string connectionString) 
      : base (connectionString) { 
    } 
} 
1

我在VS2012採用了全新的DB-產生EDMX具有單獨的類文件的Web項目 - 兩個項目都安裝了EF 6.1.1。儘管我使用的是SQL 2012,但我不得不直接編輯EDMX文件並將其從2012年更改爲ProviderManifestToken="2008".

不確定是否與Telerik Grid/EntityDataSource相關。更多提及此問題here但與VS2013相關。

+0

這對我有用,我使用VS2013。 – wilsjd 2014-07-09 18:30:44

相關問題