问题
I'm using Code First. Everything works just fine (inserts, updates, selects) everything is tested. The problem comes when I try to use the web services. I get the error "System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.". Looking at the inner exception I get this message "Could not determine storage version; a valid storage connection or a version hint is required.".
The web service Code:
/// <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;
}
}
The DAO code:
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;
}
}
The Context class:
public VirtusCloudCoreContext()
{
Database.SetInitializer<VirtusCloudCoreContext>(new VirtusCloudCoreContextInitializer());
this.Database.Connection.ConnectionString = "Data Source=localhost\SQLEXPRESS;Database=DatabaseName;User Id=******;Password=*******;" ;
}
I get the exception when I try to get the user.... Any ideas?
回答1:
This error occurs often when the connection string is wrong but I think in your case it's because you're trying to manually set the connection string.
Try making your context inherit from DbContext and take a connection string in your constructor which it passes through to the base constructor, like this:
public class VirtualCloudCoreContext : DbContext {
public VirtualCloudCoreContext(string connectionString)
: base (connectionString) {
}
}
回答2:
I'm using a new DB-generated EDMX in VS2012 Web Project with a separate class file - both projects have EF 6.1.1 installed. Even though I'm using SQL 2012, I had to edit the EDMX file directly and change it to ProviderManifestToken="2008"
from 2012.
Not sure if related to Telerik Grid/EntityDataSource or not. More mention of this issue here but related to VS2013.
来源:https://stackoverflow.com/questions/8563048/error-when-using-code-first-in-web-service-system-data-providerincompatibleexce