Wie verwendete ich Microsoft.Data.sqlclient mit Microsoft.aspnet.Identity.EntityFramework?C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie verwendete ich Microsoft.Data.sqlclient mit Microsoft.aspnet.Identity.EntityFramework?

Post by Anonymous »

Ich habe ein ASP.NET -MVC -Webprojekt auf .NET 4.8, das Azure SQL für Host -Benutzer verwendet (Benutzer (

Code: Select all

aspnetusers
) und die microsoft.aspnet.identity.entityFramework werden verwendet, um mit diesen Tabellen zu arbeiten. Dies funktioniert in meinem anderen Projekt normal, aber in diesem Fall die Microsoft.aspnet.Identity.EntityFramework referenzsystem.data.sqlclient habe ich viele Möglichkeiten ausprobiert und konnte es nicht zum Laufen bringen.

Code: Select all

public class SetMicrosoftDataSqlClient : DbConfiguration
{
public SetMicrosoftDataSqlClient()
{
SetProviderServices("System.Data.SqlClient", SqlProviderServices.Instance);
}
}

[DbConfigurationType(typeof(SetMicrosoftDataSqlClient))]
public class ApplicationIdentityDbContext : IdentityDbContext
{
public ApplicationIdentityDbContext(string connectionString) : base(new Microsoft.Data.SqlClient.SqlConnection(connectionString), false) {

DbConfiguration.SetConfiguration(new SetMicrosoftDataSqlClient());
}

public static ApplicationIdentityDbContext Create()
{
var connectionString = ConfigurationManager.ConnectionStrings["IdentityDb"].ConnectionString;
return new ApplicationIdentityDbContext(connectionString);
}
}
< /code>
Fehler: < /p>
Server Error in '/' Application.

Unable to cast object of type 'Microsoft.Data.SqlClient.SqlConnection' to type 'System.Data.SqlClient.SqlConnection'.

Description: An unhandled exception occurred during the execution of the current web request.  Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Unable to cast object of type 'Microsoft.Data.SqlClient.SqlConnection' to type 'System.Data.SqlClient.SqlConnection'.

Source Error:

Line 2217:
Line 2218:            // Is this email in our system?
Line 2219:            user = await this.FindByEmailAsync(email);
Line 2220:
Line 2221:            if (user == null)

Source File: F:\Repos\SBMP\WebApp\SBMP\Infrastructure\ApplicationUserManager.cs    Line: 2219

Stack Trace:

[InvalidCastException: Unable to cast object of type 'Microsoft.Data.SqlClient.SqlConnection' to type 'System.Data.SqlClient.SqlConnection'.]
System.Data.SqlClient.SqlCommand.set_DbConnection(DbConnection value) +26
System.Data.Common.DbCommand.set_Connection(DbConnection value) +9
System.Data.Entity.Internal.InterceptableDbCommand.set_DbConnection(DbConnection value) +9
System.Data.Common.DbCommand.set_Connection(DbConnection value) +9
System.Data.Entity.Core.Common.Utils.CommandHelper.SetStoreProviderCommandState(EntityCommand entityCommand, EntityTransaction entityTransaction, DbCommand storeProviderCommand) +62
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.PrepareEntityCommandBeforeExecution(EntityCommand entityCommand) +155
System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) +25
System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute(ObjectContext context, ObjectParameterCollection parameterValues) +735
System.Data.Entity.Core.Objects.c__DisplayClass41_0.b__1() +85
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +292
System.Data.Entity.Core.Objects.c__DisplayClass41_0.b__0() +132
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +189
System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +212
System.Data.Entity.Core.Objects.ObjectQuery`1.b__31_0() +11
System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() +39
System.Linq.Enumerable.Single(IEnumerable`1 source) +113
System.Data.Entity.Core.Objects.ELinq.c__14`1.b__14_3(IEnumerable`1 sequence) +7
System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle(IEnumerable`1 query, Expression queryRoot) +25
System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute(Expression expression) +59
System.Data.Entity.Internal.Linq.DbQueryProvider.Execute(Expression expression) +70
System.Linq.Queryable.Count(IQueryable`1 source, Expression`1 predicate) +234
System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey) +597
System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey) +39
System.Data.Entity.Migrations.History.HistoryRepository.GetLastModel(String& migrationId, String&  productVersion, String contextKey) +58
System.Data.Entity.Internal.InternalContext.QueryForModel(DatabaseExistenceState existenceState) +39
System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata, DatabaseExistenceState existenceState) +52
System.Data.Entity.Internal.InternalContext.CompatibleWithModel(Boolean throwIfNoMetadata, DatabaseExistenceState existenceState) +54
System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +109
System.Data.Entity.Internal.c__DisplayClass66_0`1.b__0() +76
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +372
System.Data.Entity.Internal.c.b__58_0(InternalContext c) +9
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +129
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +196
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +86
System.Data.Entity.Internal.InternalContext.Initialize() +30
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +16
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +38
System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken) +138
System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(IQueryable`1 source, Expression`1 predicate) +145
Microsoft.AspNet.Identity.EntityFramework.d__67.MoveNext() +402
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +29
SBMP.Infrastructure.d__22.MoveNext() in F:\Repos\SBMP\WebApp\SBMP\Infrastructure\ApplicationUserManager.cs:2219
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +29
SBMP.Controllers.d__2.MoveNext() in F:\Repos\SBMP\WebApp\SBMP\Controllers\LoginController.cs:64
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
System.Web.Mvc.Async.c__DisplayClass8_0.b__1(IAsyncResult asyncResult) +17
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
System.Web.Mvc.Async.c__DisplayClass11_0.b__0() +58
System.Web.Mvc.Async.c__DisplayClass11_2.b__2() +228
System.Web.Mvc.Async.c__DisplayClass7_0.b__1(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
System.Web.Mvc.Async.c__DisplayClass3_5.b__4() +32
System.Web.Mvc.Async.c__DisplayClass3_0.b__1(IAsyncResult asyncResult) +91
System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
System.Web.Mvc.c.b__152_1(IAsyncResult asyncResult,  ExecuteCoreState innerState) +11
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
System.Web.Mvc.c.b__151_2(IAsyncResult asyncResult, Controller controller) +13
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
System.Web.Mvc.c.b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +577
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post