Skip to content

Commit a7ba415

Browse files
committed
waiting for sql server to start
1 parent b5a5158 commit a7ba415

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

azure-pipelines.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,21 +264,30 @@ jobs:
264264
265265
# Wait for SQL Server to be ready
266266
echo "Waiting for SQL Server to start..."
267-
for i in {1..60}; do
268-
if docker exec $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $(TestAppPassword) -Q "SELECT 1" > /dev/null 2>&1; then
269-
echo "SQL Server is ready after $i attempts"
267+
268+
# First, wait for the container to be running and SQL Server service to be listening
269+
for i in {1..30}; do
270+
if docker logs $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) 2>&1 | grep -q "SQL Server is now ready for client connections"; then
271+
echo "SQL Server service is ready after $i attempts ($(($i * 2)) seconds)"
270272
break
271273
fi
272-
echo "Attempt $i: SQL Server not ready yet, waiting 5 seconds..."
273-
sleep 5
274+
echo "Attempt $i: Waiting for SQL Server service to be ready, checking again in 2 seconds..."
275+
sleep 2
274276
done
275277
276-
# Final verification
277-
if ! docker exec $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $(TestAppPassword) -Q "SELECT 1" > /dev/null 2>&1; then
278-
echo "SQL Server failed to start properly after 5 minutes"
278+
# Additional wait to ensure full initialization
279+
echo "Waiting additional 10 seconds for full SQL Server initialization..."
280+
sleep 10
281+
282+
# Verify we can connect using a simple network test first
283+
echo "Testing SQL Server connectivity..."
284+
if ! timeout 30 bash -c 'until echo > /dev/tcp/localhost/1433; do sleep 1; done'; then
285+
echo "Cannot connect to SQL Server on port 1433"
279286
docker logs $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest)
280287
exit 1
281288
fi
289+
290+
echo "SQL Server is ready and accepting connections"
282291
displayName: Install SQL Server
283292
284293
- script: |

0 commit comments

Comments
 (0)