microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
343 stars 60 forks source link

Ensure sqlcmd query doesn't return error after sqlcmd start #209

Open stuartpa opened 1 year ago

stuartpa commented 1 year ago

Right now sqlcmd start does not block waiting for SQL Server to be running and ready for client connections.

So if sqlcmd query is immediately run, it will fail with:

C:\src\go-sqlcmd\cmd\modern>sqlcmd query
EOF
Error: EOF

We either need to make sqlcmd start have a blocking option so it doesn't return until SQL is ready for connections, or sqlcmd query and sqlcmd open ads etc. all block waiting for connection to succeed (up to timeout)

As part of testing, I have tried blocking sqlcmd start until the errorlog prints "recovery complete" which is the last entry in a normal successful start up, and sqlcmd query still fails with the above error message for a few seconds.

apoorvdeshmukh commented 1 year ago

Can we have 'sqlcmd status' command which attempts to establish connection and returns if sql server is ready to accept connection or not? That way even applications can use this command to check sql server status and then decide accordingly whether to execute their workload or not.

shueybubbles commented 1 year ago

the answer to the question "is sql server available" is only valid at the point in time you ask it. It could go down a second later.

I'd expect the connection timeout to be a value of the config entry for a connection with our typical default of 30 seconds.