【发布时间】:2014-01-08 17:17:52
【问题描述】:
我在我的项目中使用EF as Design tool 资源。我的解决方案中有三个不同的项目。
DTO - 具有 DbContext 和 DTO 对象以及返回元数据的方法,如示例中所述。
Service - 具有 WebApi 方法并从 DTO 项目调用 getmetaData 并将字符串返回为 -
[BreezeController]
public class PersonController : ApiController
{
[HttpGet]
public string MetaData()
{
return new LifeAudit_DTO.DtoMetaData().MetaData();
}
}
3。第三个项目作为 WebApi 项目(使用 vs2013)有路由信息和引用服务库,这是我的主界面(UI)项目。
- 我正在使用 EF6 和 Nuget Project 的最新 Breeze。
-
我将 Database init 设置为 null,以下是我的 Datacontext 代码 -
internal class LifeAuditDbContext : DbContext { static LifeAuditDbContext() { Database.SetInitializer<LifeAuditDbContext>(null); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new PersonDtoConfiguration()); } public DbSet<Person> Person { get; set; } } -
在调用服务时出现以下错误 -
{ $id:“1”, $type: "System.Web.Http.HttpError, System.Web.Http", 消息:“发生错误。”, ExceptionMessage: "从数据库获取提供者信息时发生错误。这可能是由于 Entity Framework 使用了不正确的连接字符串造成的。请检查内部异常以获取详细信息并确保连接字符串正确。", 异常类型:“System.Data.Entity.Core.ProviderIncompatibleException”, StackTrace:“在 System.Web.Http.ApiController.d_1.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪---在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task任务)在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在 System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()", InnerException: { $id: "2", $type: "System.Web.Http.HttpError, System.Web.Http", Message: "An error has occurred.", ExceptionMessage: "The provider did not return a ProviderManifestToken string.", ExceptionType: "System.Data.Entity.Core.ProviderIncompatibleException", StackTrace: " at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection)", InnerException: { $id: "3", $type: "System.Web.Http.HttpError, System.Web.Http", Message: "An error has occurred.", ExceptionMessage: "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)", ExceptionType: "System.Data.SqlClient.SqlException", StackTrace: " at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction)在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,布尔调用者HasConnectionLock,布尔异步关闭)在 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,布尔ignoreSniOpenTimeout,Int64 timerExpire,布尔加密,布尔trustServerCert,布尔integratedSecurity,布尔withFailover)在System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字符串newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,字符串 newPassword,SecureString newSecurePassword,布尔重定向用户实例,SqlConnectionString connectionOptions,SqlCredential 凭据,TimeoutTimer 超时)在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer 超时,SqlConnectionString connectionOptions,SqlCredential凭据,字符串 newPassword,SecureString newSecurePassword,布尔重定向用户实例)在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity 身份,SqlConnectionString connectionOptions,SqlCredential 凭据,对象 providerInfo,字符串 newPassword,SecureString newSecurePassword,布尔重定向用户实例,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData)在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项,DbConnectionPoolKey poolKey,对象 poolGroupProviderInfo,DbConnectionPo ol pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) 在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions,DbConnectionInternal oldConnection)在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,布尔allowCreate,布尔onlyOneCheckConnection,DbConnectionOptions userOptions , DbConnectionInternal& 连接) 在 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 重试, DbConnectionOptions userOp System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) 在 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 次重试)在 System.Data.Entity.SqlServer.SqlProviderServices 的 System.Data.SqlClient.SqlConnection.Open() 处。c_DisplayClass2f.b_2d() 在 System.Data.Entity.SqlServer .DefaultSqlExecutionStrategy.c_DisplayClass1.b__0() 在 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action1 act) 在 System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection (DbConnection sqlConnection, Action`1 act) 在 System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifestToken(DbConnection 连接) 在 System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest令牌(DbConnection 连接)" } } }
看起来它尝试使用 EF 连接,但我传递的是 null。
任何帮助将不胜感激。
谢谢, 达尔吉特
【问题讨论】:
-
看起来您没有将上下文用于元数据only。
-
谢谢,我会在这个周末尝试并告诉你。感谢您的回复。