microsoft / vscode-mssql

Visual Studio Code SQL Server extension.
Other
1.51k stars 449 forks source link

[Bug] - Issue with "Select Top 1000/Script as Create/Script as Drop" options. #16942

Open kraghu306 opened 3 years ago

kraghu306 commented 3 years ago

Environment Details:

Steps to Reproduce:

  1. Open Visual studio code
  2. Click on Add Connection Button(+) and insert the valid Server Name or ADO.NET ConnectionString
  3. After adding the server move to database expand it and select Tables and expand then right click a selected Tables and Select Top 1000 option.
  4. Once selected Top 1000 option, an error message displays on the below right corner. PS: I have tried other option like "Select top 1000", "Script as Create", "Script as Drop", same error for all.

Error Details: Select top 1000: Error running command mssql.scriptSelect: undefined. This is likely caused by the extension that contributes mssql.scriptSelect.

Script as Create: Error running command mssql.scriptCreate: undefined. This is likely caused by the extension that contributes mssql.scriptCreate.

Script as Drop: Error running command mssql.scriptDelete: undefined. This is likely caused by the extension that contributes mssql.scriptDelete.

mssql: Failed to connect: System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0. at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue) at System.Data.Common.DbConnectionOptions.ParseInternal(Dictionary2 parsetable, String connectionString, Boolean buildChain, Dictionary2 synonyms, Boolean firstKey) at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Dictionary`2 synonyms, Boolean useOdbcRules) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.CreateConnectionStringBuilder(ConnectionDetails connectionDetails) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Connection\ConnectionService.cs:line 1096 at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.BuildConnectionString(ConnectionDetails connectionDetails) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer\Connection\ConnectionService.cs:line 1081 at Microsoft.SqlTools.ServiceLayer.Connection.ConnectionService.TryOpenConnection(ConnectionInfo connectionInfo, ConnectParams connectionParams) in D:\a\1\s\src\Microsoft.SqlTools.ServiceLayer[]\Connection\ConnectionService.cs:line 529

Expected: Once selected Top 1000 option, Result Window should open with the display of top 1000 entries from the table.

Image attached below: image

cssuh commented 3 years ago

Hi, thank you for the bug report. What kind of authentication is this for? Is it SQL Login, Integrated, or Azure MFA? Does it happen for multiple different DBs/tables?

sdbarron commented 3 years ago

Hi, I'm newly experiencing the same (found this via Bing-ing the error message). It was working just fine for me a day or two ago. Since then, I installed a bunch of Windows 10 updates last night - which probably updated a bunch of .NET - just a guess!

To your question, above, @cssuh, mine is just vanilla SQL Login. Here's a (redacted) connection string. "Server=111.111.111.111;Database=my_database;User Id=my_username;Password=my_password;"

I really only have this one database but it happens to any Table and also Stored Procedures.

Version: 1.53.2 (user setup) Commit: 622cb03f7e070a9670c94bae1a45d78d7181fbd4 Date: 2021-02-11T11:48:04.245Z Electron: 11.2.1 Chrome: 87.0.4280.141 Node.js: 12.18.3 V8: 8.7.220.31-electron.0 OS: Windows_NT x64 10.0.19042

Please me know if there's anything I can add to help, thanks!

kraghu306 commented 3 years ago

@cssuh : Any right click operation on the table is throwing the error(such as "Select top 1000", "Script as Create", "Script as Drop", same error for all). But if we try right click operations on server(such as "New Query") it opens a SQL tab and we can try our queries it will work. but the above table operations throws errors.

Same error for any databases/tables.

sdbarron commented 3 years ago

Update: I removed my connection from the Extension and re-added it and right-click tools seem to be working again! I know that doesn't make sense given the actual error message but it worked for me.

I've had wonky success in between VSCode sessions with the connection working. Sometimes it shows up as the IP address AND also the optional name - and removing one removes both. I need to delete and re-add the connection every 2-3 sessions. Not to create a distraction - that's absolutely a separate issue - but maybe it can help anyone experiencing this right-click tool issue.

SomeoneIsWorking commented 2 years ago

Update: I removed my connection from the Extension and re-added it and right-click tools seem to be working again! I know that doesn't make sense given the actual error message but it worked for me.

This works for me but gets broken again after restarting vscode