mtxr / SublimeText-SQLTools

SQLTools for Sublime Text 3
https://code.mteixeira.dev/SublimeText-SQLTools/
GNU General Public License v3.0
177 stars 40 forks source link

Support for MSSQL #120

Closed anengineerdude closed 6 years ago

anengineerdude commented 7 years ago

Issue Type

Description

No examples/support for MSSQL connections currently. Please help to support Microsoft SQL connections.

mkormendy commented 7 years ago

This has already been addressed, please see issue: https://github.com/mtxr/SQLTools/issues/52

mkormendy commented 7 years ago

Per Issue #52 for some reason all my my executions of queries performed on Sublime Text 3 on MacOS, result in the following output:

Sqlcmd: Warning: The last operation was terminated because the user pressed CTRL+C.

tkopets commented 7 years ago

@mkormendy Are you saying that it used to work before with your custom configuration, but now it doesn't work anymore?

tkopets commented 7 years ago

I've added basic support for MSSQL in the recent pull request #135. As a starting point, I used config listed in #52 by @mkormendy and tried to make it work with the latest version of SQLTools. So far it was tested and appears to be working on my local Windows machine. Testing it on Mac and Linux would require setting up a lot of things and I'm not sure I will be able to do it in next few days. I would appreciate if you can help testing MSSQL support on Mac, Linux. If you do please make sure to remove all the additional configuration you added to your SQLTools settings file. You will find examples of how to configure the connection in default Connections file.

mkormendy commented 7 years ago

@tkopets re: https://github.com/mtxr/SQLTools/issues/120#issuecomment-325948610, no it never worked.

I performed some testing on the command line directly with MacOS homebrew version of sqlcmd. While the format is identical to the Windows CLI,.. SQLTools seems to not wait for the response from the sqlcmd command before cutting the process off, using the configuration suggested in issue #52.

Let me pull your latest changes and test.

tkopets commented 7 years ago

By the way there is a release version already available. https://blogs.technet.microsoft.com/dataplatforminsider/2017/05/16/sql-server-command-line-tools-for-macos-released/

mkormendy commented 7 years ago

Yeah I tapped the Homebrew install on the release cask, so I'm working with the latest.

mkormendy commented 7 years ago

I was able to set it up, but I get a different error now:

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : TCP Provider: Error code 0x2726. Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

The command line method still works properly and outputs the records.

tkopets commented 7 years ago

The command line method still works properly and outputs the records.

Can you post the command line that works for you? So I can compare with what is being generated by SQLTools.

tkopets commented 7 years ago

I started testing sqlcmd on Mac and I found that sqlcmd on Mac does not work with standard input and result in error message you posted above:

Sqlcmd: Warning: The last operation was terminated because the user pressed CTRL+C.

Here is a simple test I performed: echo "select 1;" | sqlcmd -S IP,PORT -U xxx -P xxx -d xxx

Until sqlcmd is fixed to accept queries from standard input this will not work with SQLTools on Mac. Note: it is working fine and accepting sql from standard input on Windows.

I'm not even sure where to report this bug. If you have an idea, please submit this bug request to Microsoft.

mkormendy commented 7 years ago

Hrmm .. when I run the following on my Mac at the bash prompt:

sqlcmd -S "serverorIP,port" -U "username" -P "password" -d "database" -Q "select 1;"

It returns:

-----------
          1

(1 rows affected)

I don't need to pipe the query from an echo statement into the command or otherwise .. it just returns the results directly.

I have posted an issue on the github repo for the homebrew installer for the sqlcmd tools. The maintainer of the installer is also the author of the blog post, so hopefully he will be able to pass the issue along to the internal MS team.

tkopets commented 7 years ago

Thanks for submitting the bug request to homebrew installer project!!!

Yeah, executing a single command with -Q flag works for me as well, but SQLTools relies on CLI to be able to accept and process SQL commands from standard input. As seen here: https://github.com/mtxr/SQLTools/blob/072301ea9f007c73fc68af2ab15a1ab1fd403f11/SQLToolsAPI/Command.py#L60-L93

On Windows sqlcmd works with stdin as expected, but on Mac it doesn't.

nikme commented 7 years ago

Just for info; Query is executing by row, if you split query in multiple rows, without marking whole query it will give back error and execute only part where is pointer.

It would be great if nothing is selected, on run, whole code is executed; and if portion of code is selected, only that part is executed. This schema is in MS SQL SMS.

I'm posting under this issue because I'm not sure is it global decision or mssql case only.

tkopets commented 7 years ago

@nikme Please don't hijack this thread with an unrelated topic, instead create a separate issue.

mtxr commented 6 years ago

@tkopets in can test it tomorrow also test your pull request.

mtxr commented 6 years ago

Hey guys, could you please test the pull request #167 ?

It's supposed to fix this problem, but it's a quite ugly. Till MS solves sqlcmd problem, we can work it around.

mkormendy commented 6 years ago

Apologies for getting back just now, I will test this over the weekend.

tkopets commented 6 years ago

Great! If that works well for you I will prepare a new release.

tkopets commented 6 years ago

@mkormendy Have you had a chance to test this out? I plan to prepare a new release mid next week so if you don't want to mess with checking out the source code you can do it after release (via Package Control).

mkormendy commented 6 years ago

I tested this. It works as expected now! SUCCESS!