我有一个使用EF代码优先的asp.net MVC3项目.对于我的单元测试,我一直在使用SQL Server CE 4.0和SQL Server 2008 Express.两者都与EF一起完美地生成了我的数据库.
但是,当我在单元测试之外运行我的应用程序并将其指向我的连接字符串时,我得到了错误
ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串
我已经阅读了关于此的MS文档,看起来这是SqlVersionEF模型生成的标记.问题是我使用代码第一种方法,所以我没有.edmx文件,也不知道在哪里指向我的元数据信息,因为还没有生成数据库.
我知道我的连接字符串,因为db name,username和pass是正确的,因为将它们更改为错误的值会引发预期的错误.不知道从哪里开始.
谢谢.
这是我的连接字符串:
<connectionStrings>
<add
name="SqlConnection"
providerName="System.Data.SqlClient"
connectionString="Data Source=WORKSTATION\SQLEXPRESS;Initial Catalog=CodeFirst;Integrated Security=False;
Persist Security Info=False;User ID=CodeFirst_user;Password=password1;Connect Timeout=120;MultipleActiveResultSets=True;"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud) An error occurred while executing the command definition. See the inner exception for details. bbbbInnerException:aaaa System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2'.
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior …Run Code Online (Sandbox Code Playgroud) sql sql-server linq-to-entities entity-framework entity-framework-4
应用程序:
此问题ProviderManifestToken与自动生成的edmx文件的属性有关.
根据使用的数据库版本(不同开发人员具有不同版本的数据库)从数据库更新模型,ProviderManifestToken属性的值可以设置为2008或2012.在我们停止支持SQL Server 2005之前,我们确保该属性的值保持为2005(有关更多信息,请参阅此SO文章).
我想知道2008年和2012年之间是否存在类似问题.这个属性到底有什么作用?我可以安全地将其保留为任何值,而不会在运行时造成任何问题吗?或者我应该确保始终将其设置为2008或始终设置为2012以确保应用程序与我们支持的数据库版本一起正常工作?
MSDN在描述此属性时不是很有用.它指出ProviderManifestToken是
一个字符串,用于标识正在使用的数据库服务器的版本.例如,SQL Server提供程序对SQL Server 2008使用字符串"2008".这不能为null,但可能为空.
谢谢!