dbcli / mssql-cli

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

connect sqltoolsservice over a virtual serial port #207

Open meeuw opened 6 years ago

meeuw commented 6 years ago

I'm trying to run sqltoolsservice at a remote desktop session and tunnel the json data over the same connection over a virtual serial port. This will decouple sqltoolsservice from mssql-cli and allows one to use integrated authentication without setting up kerberos etc.

I'm running the following command on linux to set up a virtual serial port: socat -v -d -d pty,raw,echo=0 pty,raw,echo=0 (on my system this yields /dev/pts/9 and /dev/pts/10) Connect to a Windows 10 system using: rdesktop windows10 -k en-us -g 1280x800 -r comport:COM1=/dev/pts/9

Connect sqltoolservice on Windows 10 (using Cygwin socat) socat /dev/ttyS0 SYSTEM:"./MicrosoftSqlToolsServiceLayer.exe --enable-logging"

I've patched mssql-cli to start socat instead of sqltoolsservice using: socat stdio /dev/pts/10

But this gives me the following errors from sqltoolsservice (infine loop):

01/06/2018 10:15:24 [VERBOSE] - Method "WriteMessage" at line 63 of D:\GitHub\sqltoolsservice\src\Microsoft.SqlTools.Hosting\Hosting\Protocol\MessageWriter.cs

    Sending message of type[Event] and method[hosting/error]

01/06/2018 10:15:24 [ERROR] - Method "ListenForMessages" at line 235 of D:\GitHub\sqltoolsservice\src\Microsoft.SqlTools.Hosting\Hosting\Protocol\MessageDispatcher.cs

    Exception occurred while receiving message: The parameter is incorrect

socat tells me the following data was forwarded:

Content-Length: 318\r
\r                                                                                                                                           
{"id": "67622053490793607341848189735903895650", "jsonrpc": "2.0", "method": "connection/connect", "params": {"Connection": {"AuthenticationType": "SqlLogin", "DatabaseName": "master", "Password": "", "ServerName": "localhost", "UserName": "sa"}, "OwnerUri": "mssql-cli-urn:uuid:7f21a298-4d32-498f-b5f3-3535fef07c77"}}

Any idea why sqltoolsservice doesn't understand this?

pensivebrian commented 6 years ago

@meeuw - you are a mad scientist! I mean that in a good way :)

If you're using UTF8 encoding for stdin and stdout, I really have no idea why the tools service wouldn't understand the connect message. You're in uncharted territory.