Подключение к linux мс sql серверу через Entity Framework 6.4 - PullRequest
0 голосов
/ 06 апреля 2020

Я в процессе миграции asp.net приложения на asp.net core приложение.

Теперь у меня есть приложение asp.net core 3.0 с Entity Framework 6.4, и я хотел бы подключить его к Linux mssql server 2019 работает в docker контейнере (image = mcr.microsoft.com / mssql / server: 2019-CU3-ubuntu-18.04).

Когда я запускаю приложение, оно выдает PlatformNotSupportedException: LocalDB is not supported on this platform.

Stacktrace:

System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, uint waitForMultipleObjectsTimeout, bool allowCreate, bool onlyOneCheckConnection, DbConnectionOptions userOptions, out DbConnectionInternal connection)
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions, out DbConnectionInternal connection)
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, out DbConnectionInternal connection)
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions)
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource<DbConnectionInternal> retry, DbConnectionOptions userOptions)
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource<DbConnectionInternal> retry)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher+<>c.<Open>b__13_0(DbConnection t, DbConnectionInterceptionContext c)
System.Data.Entity.Infrastructure.Interception.InternalDispatcher<TInterceptor>.Dispatch<TTarget, TInterceptionContext>(TTarget target, Action<TTarget, TInterceptionContext> operation, TInterceptionContext interceptionContext, Action<TInterceptor, TTarget, TInterceptionContext> executing, Action<TInterceptor, TTarget, TInterceptionContext> executed)
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
System.Data.Entity.SqlServer.SqlProviderServices+<>c__DisplayClass60_0.<UsingConnection>b__0()
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy+<>c__DisplayClass2_0.<Execute>b__0()
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute<TResult>(Func<TResult> operation)
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action<DbConnection> act)
System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action<DbConnection> act)
System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable<int> commandTimeout, DbConnection sqlConnection, string createDatabaseScript)
System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable<int> commandTimeout, StoreItemCollection storeItemCollection)
System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable<int> commandTimeout, StoreItemCollection storeItemCollection)
System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
System.Data.Entity.Migrations.DbMigrator.Update(string targetMigration)
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update()
System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func<DbMigrationsConfiguration, DbContext, MigratorBase> createMigrator, ObjectContext objectContext)
System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState)
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState)
System.Data.Entity.CreateDatabaseIfNotExists<TContext>.InitializeDatabase(TContext context)
System.Data.Entity.Internal.InternalContext+<>c__DisplayClass66_0<TContext>.<CreateInitializationAction>b__0()
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
System.Data.Entity.Internal.LazyInternalContext+<>c.<InitializeDatabase>b__58_0(InternalContext c)
System.Data.Entity.Internal.RetryAction<TInput>.PerformAction(TInput input)
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action<InternalContext> action)
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
System.Data.Entity.Internal.InternalContext.Initialize()
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
System.Data.Entity.Internal.Linq.InternalSet<TEntity>.Initialize()
System.Data.Entity.Internal.Linq.InternalSet<TEntity>.get_InternalContext()
System.Data.Entity.Infrastructure.DbQuery<TResult>.System.Linq.IQueryable.get_Provider()
System.Linq.Queryable.Single<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)

SQL сервер видим, и я могу подключиться к нему с помощью Azure Data Studio.

Я попытался указать SQL client-provider:

public class SqlDbConfiguration: DbConfiguration
{
    // providerName="System.Data.SqlClient"
    public SqlDbConfiguration()
    {
      SetProviderServices(
        SqlProviderServices.ProviderInvariantName,
        SqlProviderServices.Instance);
    }
}

Строка подключения:

Data Source=127.0.0.1,1401;Initial Catalog=database; User Id=sa; Password=<YourStrong@Passw0rd\\>;Persist Security Info=True;MultipleActiveResultSets=True;"

Что-то мне не хватает? Могу ли я даже использовать Entity Framework 6.4 в этой настройке?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...