@@ -425,19 +425,27 @@ public static IContainerService SetupTransactionProcessorContainer(String contai
425425 /// <param name="networkService">The network service.</param>
426426 /// <param name="hostFolder">The host folder.</param>
427427 /// <param name="dockerCredentials">The docker credentials.</param>
428+ /// <param name="sqlUserName">Name of the SQL user.</param>
429+ /// <param name="sqlPassword">The SQL password.</param>
428430 /// <returns></returns>
429- public static String StartSqlContainerWithOpenConnection ( String containerName ,
430- ILogger logger ,
431- String imageName ,
432- INetworkService networkService ,
433- String hostFolder ,
434- ( String URL , String UserName , String Password ) ? dockerCredentials )
431+ public static IContainerService StartSqlContainerWithOpenConnection ( String containerName ,
432+ ILogger logger ,
433+ String imageName ,
434+ INetworkService networkService ,
435+ String hostFolder ,
436+ ( String URL , String UserName , String Password ) ? dockerCredentials ,
437+ String sqlUserName = "sa" ,
438+ String sqlPassword = "thisisalongpassword123!" )
435439 {
440+ logger . LogInformation ( "About to start SQL Server Container" ) ;
436441 IContainerService databaseServerContainer = new Builder ( ) . UseContainer ( ) . WithName ( containerName ) . UseImage ( imageName )
437- . WithEnvironment ( "ACCEPT_EULA=Y" , "SA_PASSWORD=thisisalongpassword123! " ) . ExposePort ( 1433 )
442+ . WithEnvironment ( "ACCEPT_EULA=Y" , "SA_PASSWORD={sqlPassword} " ) . ExposePort ( 1433 )
438443 . UseNetwork ( networkService ) . KeepContainer ( ) . KeepRunning ( ) . ReuseIfExists ( ) . Build ( ) . Start ( )
439444 . WaitForPort ( "1433/tcp" , 30000 ) ;
440445
446+ logger . LogInformation ( "SQL Server Container Started" ) ;
447+
448+ logger . LogInformation ( "About to SQL Server Container is running" ) ;
441449 IPEndPoint sqlServerEndpoint = databaseServerContainer . ToHostExposedEndpoint ( "1433/tcp" ) ;
442450
443451 // Try opening a connection
@@ -446,53 +454,49 @@ public static String StartSqlContainerWithOpenConnection(String containerName,
446454
447455 String server = "127.0.0.1" ;
448456 String database = "SubscriptionServiceConfiguration" ;
449- String user = "sa" ;
450- String password = "thisisalongpassword123!" ;
457+ String user = sqlUserName ;
458+ String password = sqlPassword ;
451459 String port = sqlServerEndpoint . Port . ToString ( ) ;
452460
453461 String connectionString = $ "server={ server } ,{ port } ;user id={ user } ; password={ password } ; database={ database } ;";
454-
462+ logger . LogInformation ( $ "Connection String { connectionString } " ) ;
455463 SqlConnection connection = new SqlConnection ( connectionString ) ;
456464
457- using ( StreamWriter sw = new StreamWriter ( "C: \\ Temp \\ testlog.log" , true ) )
465+ while ( counter <= maxRetries )
458466 {
459- while ( counter <= maxRetries )
467+ try
460468 {
461- try
462- {
463- sw . WriteLine ( $ "Attempt { counter } ") ;
464- sw . WriteLine ( DateTime . Now ) ;
469+ logger . LogInformation ( $ "Database Connection Attempt { counter } ") ;
465470
466- connection . Open ( ) ;
471+ connection . Open ( ) ;
467472
468- SqlCommand command = connection . CreateCommand ( ) ;
469- command . CommandText = "SELECT * FROM EventStoreServers" ;
470- command . ExecuteNonQuery ( ) ;
473+ SqlCommand command = connection . CreateCommand ( ) ;
474+ command . CommandText = "SELECT * FROM EventStoreServers" ;
475+ command . ExecuteNonQuery ( ) ;
471476
472- sw . WriteLine ( "Connection Opened" ) ;
477+ logger . LogInformation ( "Connection Opened" ) ;
473478
479+ connection . Close ( ) ;
480+ logger . LogInformation ( "SQL Server Container Running" ) ;
481+ break ;
482+ }
483+ catch ( SqlException ex )
484+ {
485+ if ( connection . State == ConnectionState . Open )
486+ {
474487 connection . Close ( ) ;
475-
476- break ;
477488 }
478- catch ( SqlException ex )
479- {
480- if ( connection . State == ConnectionState . Open )
481- {
482- connection . Close ( ) ;
483- }
484489
485- sw . WriteLine ( ex ) ;
486- Thread . Sleep ( 20000 ) ;
487- }
488- finally
489- {
490- counter ++ ;
491- }
490+ logger . LogError ( ex ) ;
491+ Thread . Sleep ( 20000 ) ;
492+ }
493+ finally
494+ {
495+ counter ++ ;
492496 }
493497 }
494498
495- return $ "server= { containerName } ;user id= { user } ; password= { password } ;" ;
499+ return databaseServerContainer ;
496500 }
497501
498502 /// <summary>
0 commit comments