dbcli / mssql-cli

A command-line client for SQL Server with auto-completion and syntax highlighting
BSD 3-Clause "New" or "Revised" License
1.35k stars 191 forks source link

DAC connections with '-S localhost' fail on Linux #141

Open EvanCarroll opened 6 years ago

EvanCarroll commented 6 years ago

this does not work,

mssql-cli -A -S localhost

this works

mssql-cli -A

Seems as if -A assumes that it's not running a remote DAC connection. Probably not a safe assumption. And it's confusing that adding a -A on a working command causes it fail.

pensivebrian commented 6 years ago

I'm not able to repro any errors running mssql-cli -A -S localhost on my Windows box. What OS/python version are you using? Also, can you post the error your are seeing, and the log file from the %localappdata%\dbcli\mssqlcli\mssqlcli.log file?

EvanCarroll commented 6 years ago

Using Linux with mssql-cli -S localhost -U sa -A. Log inlined.

2018-01-16 18:51:45,205 (8663/MainThread) mssqlcli INFO - Initializing mssqlcli logging.
2018-01-16 18:51:45,207 (8663/MainThread) mssqlcli.main INFO - Default pager found in PAGER environment variable: "less -Rs"
2018-01-16 18:51:45,212 (8663/MainThread) mssqlcli.sqltoolsclient INFO - SqlToolsService process id: 8667
2018-01-16 18:51:45,212 (8663/MainThread) mssqlcli.sqltoolsclient INFO - Sql Tools Client Initialized
2018-01-16 18:51:47,166 (8663/MainThread) mssqlcli.mssqlcliclient INFO - Initialized MssqlCliClient
2018-01-16 18:51:47,167 (8663/MainThread) mssqlcli.sqltoolsclient INFO - SqlToolsClient connection request Id 247532094502864329912265845108013384440
2018-01-16 18:52:02,212 (8663/MainThread) mssqlcli.connectionservice ERROR - A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught)
2018-01-16 18:52:02,212 (8663/MainThread) mssqlcli.connectionservice ERROR - System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 35 - An internal exception was caught) ---> System.AggregateException: One or more errors occurred. (Connection refused 127.0.1.1:1434) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Connection refused 127.0.1.1:1434
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.<>c.<ConnectAsync>b__267_0(IAsyncResult iar)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Data.SqlClient.SNI.SNITCPHandle.<ConnectAsync>d__22.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait(TimeSpan timeout)
   at System.Data.SqlClient.SNI.SNITCPHandle..ctor(String serverName, Int32 port, Int64 timerExpire, Object callbackObject, Boolean parallel)
---> (Inner Exception #0) System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (0x80004005): Connection refused 127.0.1.1:1434
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at System.Net.Sockets.Socket.<>c.<ConnectAsync>b__267_0(IAsyncResult iar)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Data.SqlClient.SNI.SNITCPHandle.<ConnectAsync>d__22.MoveNext()<---

   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.<>c__DisplayClass22_0.<TryGetConnection>b__0(Task`1 _)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection.ReliableSqlConnection.<>c__DisplayClass28_0.<<OpenAsync>b__0>d.MoveNext() in D:\GitHub\sqltoolsservice\src\Microsoft.SqlTools.ServiceLayer\Connection\ReliableConnection\ReliableSqlConnection.cs:line 298
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.<TryOpenConnection>d__46.MoveNext() in D:\GitHub\sqltoolsservice\src\Microsoft.SqlTools.ServiceLayer\Connection\ConnectionService.cs:line 542
ClientConnectionId:00000000-0000-0000-0000-000000000000
2018-01-16 18:52:02,214 (8663/MainThread) mssqlcli.jsonrpc.jsonrpcclient INFO - Shutting down Json rpc client.
2018-01-16 18:52:02,214 (8663/MainThread) mssqlcli.sqltoolsclient INFO - Shutting down Sql Tools Client Process Id: 8667
pensivebrian commented 6 years ago

Thanks for the info. I can repro this on Linux. There are two workarounds (you already mentioned the first): 1) mssql-cli -A 2) mssql-cli -A -S 127.0.0.1

Since we have workarounds, this will be a lower priority bug fix, so it may be awhile until we get to this. I appreciate you exercising the DAC features of the tool. Thanks for filing!