SQL Exception during initial migration on Azure SQL Database #5274
-
Version8.2.2 Using which broker(s) did you encounter the issue?MassTransit.SqlTransport.SqlServer What are the steps required to reproduce the issue?This issue occurs during the first migration. What is the expected behavior?Works as expected with on-premises SQL Server, but throws an exception during the initial migration on Azure SQL Database. What actually happened?Hello, I'm encountering an issue with MassTransit.SqlTransport.SqlServer (v8.2.2) and connecting with Azure SQL Database. The library works as expected with on-premises SQL Server, but throws an exception during the initial migration on Azure SQL Database. The error message is: "Invalid object name 'sys.syslogins'". Any help would be appreciated. Related log output, including any exceptions16:04:15:415 INF MassTransit DbTransport creating database "XXXXX-backend-db" <Module: XXXXXBackend> <App: XXXX> ││ 16:04:15:415 ERR Hosting failed to start <Module: XXXXBackend> <App: XXXXX> ││ Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'sys.syslogins'. ││ at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) ││ at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) ││ at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose) ││ at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) ││ at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData() ││ at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData() ││ at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) ││ at Microsoft.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader(Boolean isInternal, Boolean forDescribeParameterEncryption) ││ at Microsoft.Data.SqlClient.SqlCommand.InternalEndExecuteReader(IAsyncResult asyncResult, Boolean isInternal, String endMethod) ││ at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderInternal(IAsyncResult asyncResult) ││ at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderAsync(IAsyncResult asyncResult) ││ at Microsoft.Data.SqlClient.SqlCommand.<>c.<InternalExecuteReaderAsync>b__201_1(IAsyncResult asyncResult) ││ at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) ││ --- End of stack trace from previous location --- ││ at Dapper.SqlMapper.ExecuteScalarImplAsync[T](IDbConnection cnn, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 1241 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.GrantAccess(ISqlServerSqlTransportConnection connection, SqlTransportOptions options) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1447 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateSchemaIfNotExist(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1391 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateSchemaIfNotExist(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1395 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateSchemaIfNotExist(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1395 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateDatabase(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1340 ││ at MassTransit.SqlTransport.SqlTransportMigrationHostedService.StartAsync(CancellationToken cancellationToken) in /_/src/MassTransit/SqlTransport/SqlTransport/SqlTransportMigrationHostedService.cs:line 34 ││ at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token) ││ at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation) ││ ClientConnectionId:XXXXX ││ Error Number:208,State:1,Class:16 ││ 16:04:15:415 WRN Failed to stop bus: db://XXXX-mssql.database.windows.net/XXXXX?autodelete=300 ("Not Started") <Module: XXXXXBackend> <App: XXXXX> ││ Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'sys.syslogins'. ││ at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) ││ at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) ││ at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose) ││ at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) ││ at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData() ││ at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData() ││ at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) ││ at Microsoft.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader(Boolean isInternal, Boolean forDescribeParameterEncryption) ││ at Microsoft.Data.SqlClient.SqlCommand.InternalEndExecuteReader(IAsyncResult asyncResult, Boolean isInternal, String endMethod) ││ at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderInternal(IAsyncResult asyncResult) ││ at Microsoft.Data.SqlClient.SqlCommand.EndExecuteReaderAsync(IAsyncResult asyncResult) ││ at Microsoft.Data.SqlClient.SqlCommand.<>c.<InternalExecuteReaderAsync>b__201_1(IAsyncResult asyncResult) ││ at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization) ││ --- End of stack trace from previous location --- ││ at Dapper.SqlMapper.ExecuteScalarImplAsync[T](IDbConnection cnn, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 1241 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.GrantAccess(ISqlServerSqlTransportConnection connection, SqlTransportOptions options) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1447 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateSchemaIfNotExist(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1391 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateSchemaIfNotExist(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1395 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateSchemaIfNotExist(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1395 ││ at MassTransit.SqlTransport.SqlServer.SqlServerDatabaseMigrator.CreateDatabase(SqlTransportOptions options, CancellationToken cancellationToken) in /_/src/Transports/MassTransit.SqlTransport.SqlServer/SqlTransport/SqlServer/SqlServerDatabaseMigrator.cs:line 1340 ││ at MassTransit.SqlTransport.SqlTransportMigrationHostedService.StartAsync(CancellationToken cancellationToken) in /_/src/MassTransit/SqlTransport/SqlTransport/SqlTransportMigrationHostedService.cs:line 34 ││ at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>b__15_1(IHostedService service, CancellationToken token) ││ at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation) ││ at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) ││ at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) ││ at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token) ││ at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host) ││ at Program.<Main>$(String[] args) in ...... Link to repository that demonstrates/reproduces the issueNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
You could try using the configuration callback when adding the migration service and specify CreateDatabase = false since the database already exist. It will still create the infrastructure (tables, etc.). |
Beta Was this translation helpful? Give feedback.
-
I faced kind of similar issue then I realize that with Azure SQL, we don't have access to this
|
Beta Was this translation helpful? Give feedback.
I mean, good question, but you might just have to create the schema and make sure the user has access to it, and then let MassTransit create the infrastructure in that schema. Database/schema creation and assignment of rights is typically part of "creating a database" based on how permissions work, but it's something to explore I guess.