Tag: ADS

  • Fixing the PoSh Hotkey in ADS

    I installed the PowerShell (PoSh) extension in ADS recently. This is available in the extension pane, and once installed, you get the 4th icon on the right added to your sidebar, for PoSh.

    2020-09-10 15_07_51-poshtest.ps1 - Data Analysis - Azure Data Studio

    I have the SSMS Keymap extension installed as well, since that was the first one I grabbed. This gives me keymapping to allow CTRL+E to execute queries. I have literally a decade of muscle memory here, and really wanted this to work.

    However, when I highlight code in ADS and press F8, which is what I do in VS Code, I get this:

    2020-09-11 14_42_34-poshtest.ps1 - Data Analysis - Azure Data Studio

    Not only is my PoSh code in the editor tab not executed in the Terminal, but the Server Connection pane pops open.

    This is because that’s what keymap does for F8. I can use the command palette to debug this.

    2020-09-11 14_44_14-Keyboard Shortcuts - Data Analysis - Azure Data Studio

    If I open up the keyboard shortcuts and search for F8, I find that a number of things use this.

    2020-09-11 14_44_21-Keyboard Shortcuts - Data Analysis - Azure Data Studio

    The last binding is the one that’s in effect, and you can see that the Show Connections overrides the PowerShell item.

    Fortunately, I can edit this by clicking on the left of this line.

    2020-09-11 14_45_41-Keyboard Shortcuts - Data Analysis - Azure Data Studio

    Once the dialog pops up, it is there to capture any keystrokes, so it’s hard to get a picture of this. However, with a little experimenting, I remapped this to CTRL+L, which has some bindings, but these aren’t ones I use.

    Now I see PowerShell as the last item, and if I close this tab, and go back to my code, I can press F8, and I’ll see the line executed in the terminal.

    2020-09-11 14_47_45-poshtest.ps1 - Data Analysis - Azure Data Studio

  • Creating a Quick Dashboard Widget

    I read Carlos Robles blog on creating an Azure Data Studio (ADS) insight widget and decided to try this for myself. I decided to try and get a list of object types and a count of each. Following instructions, here’s what I did.

    First, I wrote a query that would gather the types of objects and counts from sys.objects.

    2018-10-20 16_41_15-UserObjectCount.sql - Azure Data Studio

    I saved this as a file under my Documents folder. Once I had this, I ran the query and in the results, I clicked on the Chart item to the right of the results.

    2018-10-20 17_01_52-UserObjectCount.sql - Azure Data Studio

    This displays a bar chart, which is useful at times, but that’s not what I want.

    2018-10-20 17_02_02-UserObjectCount.sql - Azure Data Studio

    Instead of this, I’ll expand the Chart Type drop down. This gives me a list of a number of items I can choose. For this insight, I’ll use the table type.

    2018-10-20 16_41_30-UserObjectCount.sql - Azure Data Studio

    Once this is done, I’ll see the results I want. There is a “Create Insight” button above the chart. I’ll click this to get the JSON code that creates this.

    2018-10-20 16_41_23-UserObjectCount.sql - Azure Data Studio

    A new editor tab opens with the JSON code in it. This is just one long line of code, which isn’t as helpful or easy to work with.

    2018-10-20 16_50_48-Untitled-2 - Azure Data Studio

    CTRL+Shift+P opens the command palette. Type “format” and you’ll see the Format Document command. Once you format the code, it will be easier to read.

    2018-10-20 16_51_06-● Untitled-2 - Azure Data Studio

    The next step is to open the user settings. This is also in the command palette.

    2018-10-20 16_49_47-2017Sandbox_sandbox - Azure Data Studio

    In my ADS, I get the settings list. I can search for dashboard and I’ll find the one I want.

    2018-10-20 16_50_07-settings.json - Azure Data Studio

    If I put the cursor in the upper left, I’ll get an edit item. I can pick this and I’ll get one of two items. If I’ve never customized anything, I’ll get the “copy to user settings” option. If I have, I get the “Replace in settings” item.

    2018-10-20 16_50_15-settings.json - Azure Data Studio

    Once I’ve done this, I want to modify some code. I don’t love the search box, so I’ll delete that json widget. Then I paste in my widget code. Be sure you put this in the right place, with a comma between the widgets braces. I changed the name from “my-widget” to “User Object Count”.

    2018-10-20 17_11_36-settings.json - Azure Data Studio

    Once I do this, I save it and close it. Then I double click one of my server connections and I see my widget on the dashboard.

    2018-10-20 16_57_11-SimpleTalk Dev 2014_SimpleTalk_1_Dev - Azure Data Studio

    Pretty easy to get a query to appear on your dashboard as a chart if you want to get some insights. Any query could be used, with the results returned when you open the server connection. You can also leave the dashboard open and refresh it when convenient.

  • Adding SQL Search to Azure Data Studio

    There are a limited number of extensions available for Azure Data Studio (ADS), but one that came out early is SQL Search. This is highlighted as a recommended extension from Microsoft. Redgate worked with them early on in the lifecycle of the product to get this extension working, including helping spec out the APIs for interaction with ADS.

    2018-10-19 17_53_21-Extension_ Redgate SQL Search - Azure Data Studio

    My extensions pane is on the right, so my details are on the left. There’s a description of SQL Search as well as a link to install the extension. As with most extensions, the link takes you to a download page. For SQL Search, this is a Redgate Foundry page with a few builds. I picked the public one.

    2018-10-19 17_53_45-Redgate Foundry Labs

    Installing extensions is basically using File | Install Extensions from VSIX and picking the downloaded file. You need to approve the extension and then reload once it’s installed. You can see it installed if you re-open the extensions pane.

    2018-10-19 18_01_40-● SQLQuery1 - Azure Data Studio

    Using SQL Search

    To use this extension, you can use the CTRL+Shift+P command to bring up the command palette. When you do this, you get a way to run commands at the top of the ADS window. This is a handy tool that you will use often.

    2018-10-20 15_51_23-SQLQuery2 - Azure Data Studio

    If we type “SQL S”, we’ll get the SQL Search commands. There is a reindex command and a search command. These are the two items implemented at this time.

    2018-10-20 15_51_33-SQLQuery2 - Azure Data Studio

    The re-index command will update the SQL Search index with information from the current database connection. If you cannot find an object you need, then you might run the reindex.

    The other command allows you to search the database. If we click this one, we get a new edit box at the top of the window. Focus will be in this window, so you can type a term. For me, I know there are a number of items in this database for blogs, so let’s enter that.

    2018-10-20 15_56_20-SQLQuery2 - Azure Data Studio

    The results will appear in a new tab alongside your currently open tabs.

    2018-10-20 15_56_42-SQL Search Results_ blog - Azure Data Studio

    The results show me that I have an object name along with the schema and database. We see the type of the object and then the way the object was matched. Next to the object name, there is a circle with an ellipsis. If we click this, we have a couple of choices for what to do with our results.

    2018-10-20 15_57_06-SQL Search Results_ blog - Azure Data Studio

    We can highlight this object in our object explorer, which will, well, do nothing for me. I suspect that the call from the extension to the servers Object Explorer is flaky. Even if I open the Servers pane and then click “Reveal in Object Explorer”, nothing happens. I see whatever I had opened in the Servers Pane.

    2018-10-20 16_04_14-SQL Search Results_ blog - Azure Data Studio

    If I close the server pane and instead click View Definition, I get a split pane on the right with the object definition. I can resize this as needed, but this is a view only pane. I can’t edit or execute this code. It’s for reference, which can be helpful when coding, but is of limited use.

    2018-10-20 16_05_16-SQL Search Object Definition_ BlogArchiveModDate - Azure Data Studio

    I can  copy this code for another window if I click the start and end places in the search results while holding the Shift key. Then I right click in the window and select Copy.

    2018-10-20 16_10_10-SQL Search Object Definition_ test Disallow Blank Titles - Azure Data Studio

    This is a limited use extension, but it does allow one to find code quicker than browsing through the Object Explorer. We can keep the search results up as a separate pane, so that we can use this as a pick list if we were looking for all the dependent objects for an object.

    One nice touch from ADS is that if you CTRL+Shift+P again, the SQL Search commands appear at the top as recently used items.

    2018-10-20 16_14_17-SQL Search Results_ blog - Azure Data Studio

    Give SQL Search a try and let us know what you think.

  • Better Keyboard Extensions in Azure Data Studio

    I used to use ALT+X to execute queries in SSMS. I spent years with this shortcut, but as I started to present more, CTRL+E felt more natural. I’ve now grown used to that, so when I typed CTRL+E in Azure Data Studio (ADS), I was less than pleased.

    2018-10-19 17_06_57-● SQLQuery1 - Azure Data Studio

    Even trying to get help here didn’t help.

    2018-10-19 17_07_18-● SQLQuery1 - Azure Data Studio

    I actually had a conversation with Kevin Cunnane when this was SOS and he pointed me to the keymap extension.  You can get this by clicking the extensions icon on the left side of ADS:

    2018-10-19 17_12_50-● SQLQuery1 - Azure Data Studio

    Once you do this, search for keymap, and you’ll see Kevin’s extension.

    2018-10-19 17_13_03-● SQLQuery1 - Azure Data Studio

    You can see details for the extension on the right.

    2018-10-19 17_18_34-Extension_ SSMS Keymap - Azure Data Studio

    When you click “Install”, you’ll go to Kevin’s repo on Github. Click the link to download the VSIS extension. This gets saved in your Downloads folder (or wherever you have downloads going).

    Go back to ADS and use the File menu to find the VSIS installer.

    2018-10-19 17_18_28-Extension_ SSMS Keymap - Azure Data Studio

    Browse and double click the VSIX file you downloaded. You’ll see a message in the lower right of ADS.

    2018-10-19 17_19_48-Extension_ SSMS Keymap - Azure Data Studio

    Click Yes, or no, but if you click No, this won’t install. In a few seconds, if you clicked Yes, you’ll see this:

    2018-10-19 17_19_57-Extension_ SSMS Keymap - Azure Data Studio

    Click Reload, and ADS will close and reopen. Your query window should still be there, and CTRL+E will pop the connection dialog, since the connection closed. Once you connect, the query will run with CTRL+E

    2018-10-19 17_20_10-● SQLQuery1 - Azure Data Studio

    The full list of key mappings is available on the repo or in the package.json file.