Thursday, January 25, 2018

Executing a stored procedure in Microsoft SQL Operations Studio(SQLOPS)

Executing a stored procedure is as easy as running query in SQLOPS.

For example, I restored the Northwind database from a backup file from CodePlex site to the default instance of SQL Server 2017 Developer's Edition.

I connected to the SQL Server 2017 in Microsoft SQLOPS as shown. Here you can see all the objects in the server.



SP_SQLOPS_0

Right click the stored procedure (herein, dbo.CustOrderHist) to display a pick list as shown.



SP_SQLOPS_1

Click Script as Execute.
A query is created as shown:


SP_SQLOPS_2

In the TODO section add-in the value of CustomerID.
Look up the data type of CustomerID as shown here:


SP_SQLOPS_3


You need to modify this query somewhat to see the results (this is Preview software). Add statements to the SQLOPS created script to read as shown here:
---------------------
USE Northwnd
GO
DECLARE @RC int
DECLARE @CustomerID
nchar(5)
-- TODO: Set parameter values here.
Set @CustomerID='ALFKI'
EXECUTE @RC = [dbo].[CustOrderHist]
   @CustomerID
GO
-----------------
Now click Run and you can see the response as shown:

That's all.

JSON response from a SQL Query in SQL Server 2016

JSON is supported in SQL Server and it is very easy to obtain JSON formatted response from a query easily. For example,

while connected to Northwind database you get the JSON formatted data by running a query such as this one using the Products table:
---------------------------------
SELECT        ProductName, QuantityPerUnit, UnitPrice
FROM            Products FOR JSON Auto;
---------------------------------
The response will be as shown:


JSON_0

You could also return a single row of data as shown by running this query:
-----------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
WHERE ProductID=5
For JSON AUTO
-------------------------


JSON_1

The result comes in an array even if the returned data is just one row.

You could remove the array wrapper ([ ]) surrounding the result set by the following query:
-------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
For JSON AUTO, WITHOUT_ARRAY_WRAPPER
---------------------------------------

JSON_2

Notice that the array wrapper is gone in the result set.

You can further qualify where the data (Which table, for example) by adding a 'root' element by issuing this query:
------------------------
SELECT [ProductID]
      ,[ProductName] 
FROM [Northwind].[dbo].[Products]
For JSON AUTO, Root('Products')
------------------------

JSON_3

You are not allowed to use WITHOUT_ARRAY_WRAPPER and Root in the same sql query because you get the following message, if you do:

Msg 13620, Level 16, State 1, Line 5
ROOT option and WITHOUT_ARRAY_WRAPPER option cannot be used together in FOR JSON. Remove one of these options.

I am using SQL Server 2016 Developer's edition on my Windows 10 Pro laptop.

If you are new to JSON read the following:


If you are motivated to learn there are more here:


Wednesday, January 24, 2018

Connecting to SQL Server 2017 using Microsoft SQL Operations Studio with an IP Address

Take for example, SQL Server 2017 Developer's edition. It is the latest release version. When you install it you can only access using 'localhost' as shown.

Enter localhost
SQLServrConfig0

Click Connect and you are connected as shown.


SQLServrConfig00

Now instead of localhost, try the IPAddress as shown.


SQLServrConfig4

Trying to Connect you get the following message.


The reason for this is that the Protocols for MSSQLSERVER (the instance we are considering) has only Shared Memory enabled as in the SQL Server Configuration Manager.

SQLServrConfig1

The error message indicated that it was due to Named Pipe provider error.

Let us enable Named Pipes protocol in SQL Server Configuration Manager as shown.

SQLServrConfig2

Make a note that when you change (enable/disable), you need to stop and start the server. You can do this in SQL Server Configuration Manager.

Now attempt to connect using IPAddress as before.

SQLServrConfig4

Click Connect and you are connected as shown.


SQLServrConfig3

That is all there is to it. 

Monday, January 22, 2018

Restoring legacy database to SQL Server 2017 using Microsoft SQL Operations Studio

You can restore a database to SQL Server using the SQL Server Management Studio(SSMS). It is a feature rich tool for restoring and backing up databases. Besides restoring and backing up SSMS can carry out a ton of other tasks.

Here is an example of using SSMS to restore a database to SQL Server.

Why use Microsoft SQL Opertions Studio?

For one thing it has small foot print and it is free (preview now). It is lightweight and can do only a few of the things. You can restore a database with fewer clicks than with SSMS.

On my Windows 10 Professional, I have installed SQL Server 2017 Developer edition. I will restore the Northwind database from its backup file on CodePlex. Being a preview, Microsoft SQL Operations Studio has a few kinks and I have a workaround to bypass the kink and get the result.

Watch the video for the restore opeation:
https://www.youtube.com/edit?o=U&video_id=-KOXjlRACSU

Restore operation using Windows PowerShell
https://hodentekmsss.blogspot.com/2016/03/easy-way-to-backup-sql-server-database.html

Read many more related PowerShell posts here.

Friday, January 19, 2018

Generating query output in JSON is easy using Microsoft Operations Studio

Installing the January Preview (latest as of now) Microsoft SQL Operations Studio is easy. Follow the steps here .

Connecting to SQL Server 2016 is explained in details here.

Connection is very easy, especially if you are using Windows Integrated authentication as shown here:


SQLOPS_JanPublicPreview_01

This screen in the January Preview is not quite what I expected. The two tabs (RECENT CONNECTIONS which is active and SAVED CONNECTIONS greyed out) in the background does not do anything.

Just click Connect and you are connected as shown.


SQLOPS_JanPublicPreview_02


Either we can run a new query or browse and get a saved query (with extension .sql).  I am trying a saved query from an earlier connection with an earlier version.


SQLOPSStudio_03

The query is displayed in the MSFT SQLOPS application as shown. But I see a reddish no-no on the connection on the left.


SQLOPS_JanPublicPreview_03
Anyway, just click Run to execute the query and the response appears in a pane below as shown.


SQLOPS_JanPublicPreview_04

Since this is a query from a query using another connection, the connection screen is displayed as shown.

Enter the conneciton information as before. The data entered is accpeted and the query is executed as shown.


SQLOPS_JanPublicPreview_05

Now click on the Save as JSON on the right. You will save it to the default folder that opens. After saving to folder JSON fromatted query result is displayed as shown.


SQLOPS_JanPublicPreview_06

It could not be simpler than this, really.

Read related article here:
https://hodentekmsss.blogspot.com/2016/06/exporting-data-from-sql-server-2016-as.html

Thursday, January 18, 2018

Installing Microsoft SQL Operations Studio (preview) on Windows 10

Screen shots taken while installing the January Public Preview (ver 0.25.4) of Microsoft SQL Operations Studio (MSFT SQLOPS) are included in this post. The details of this version are as shown:


SQLOPS_JANPreview.png


MSFT SQLOPS will be installed on a Windows 10 Professional on a Dell Laptop.


SQLOPS_JanPublicPreview9_Win.png

We will use the installer route to install. You start installing by double clicking the installer file you downloaded.


SQLOPS_JanPublicPreview2



SQLOPS_JanPublicPreview3

Accept license terms and click Next.


SQLOPS_JanPublicPreview4




SQLOPS_JanPublicPreview5



SQLOPS_JanPublicPreview6



SQLOPS_JanPublicPreview7



SQLOPS_JanPublicPreview8

It is installed and it is launched as shown



Microsoft SQL Operations Studio January Preview - enhancements & Fixes

I had the November 2017 version (0.23.6) after which a December version (0.24.1) was released. I skipped this version for no better than I had other things to do.

The present version is 0.25.4 


These are the enhancements (taken from Microsoft site):

  • Saved Server connections are available in the Connection Dialog.
  • Enable Hot exit. Hot exit is off by default, to enable see Hot exit setting.
  • Tab-coloring based on Server Group. Tab coloring is off by default, to enable see Tab color setting.
  • Change Server name to Server in the Connection Dialog.
  • Fix broken Run Current Query command.
  • Fix drag-and-drop breaking scripting bug.
  • Fix incorrect pinned Start Menu icon.
  • Fix missing Azure Account branding icon.

Microsoft SQL Operations Studio- January Public Preview is ready

You can downlaod it from here for all of the three platforms, Windows, macOS and Linux.
https://docs.microsoft.com/en-us/sql/sql-operations-studio/download

Before using review the following:

What is SQLOPS?
https://hodentekmsss.blogspot.com/2017/12/light-weight-database-management-and.html

Description of user interface:
https://hodentekmsss.blogspot.com/2017/12/sql-operations-studio-user-interface.html

Connecting to SQL Server 2016 using SQLOPS:
http://hodentekhelp.blogspot.com/2017/12/how-do-you-connect-to-sql-server-using.html

It is very easy to download and run immediately (Windows Installer and ZIP).

Using Installer:
Download and run the SQL Operations Studio (preview) installer for Windows.
Start the SQL Operations Studio (preview) app.
Link to click: https://go.microsoft.com/fwlink/?linkid=866480

Using the ZIP file:
Download SQL Operations Studio (preview) .zip for Windows.
Browse to the downloaded file and extract it.
Run \sqlops-windows\sqlops.exe
Link to click: https://go.microsoft.com/fwlink/?linkid=866479

Supported platforms:
Windows
Windows 10 (64-bit)
Windows 8.1 (64-bit)
Windows 8 (64-bit)
Windows 7 (SP1) (64-bit) - Requires KB2533623
Windows Server 2016
Windows Server 2012 R2 (64-bit)
Windows Server 2012 (64-bit)
Windows Server 2008 R2 (64-bit)
+
macOS
macOS 10.13 High Sierra
macOS 10.12 Sierra

Linux
Red Hat Enterprise Linux 7.4
Red Hat Enterprise Linux 7.3
SUSE Linux Enterprise Server v12 SP2
Ubuntu 16.04

Uninstall:
Since it is preview, if you need to uninstall at a later date:
------------------------------------------
If you installed SQL Operations Studio (preview) using the Windows installer, then uninstall the same way you remove any Windows application.

If you installed SQL Operations Studio (preview) with a .zip or other archive, then simply delete the files.
-------------------------------------------
Enjoy!

Connecting to SQL Server using Microsoft SQL Operation Studio

It is so easy to connect to SQL Server database.

Read here: What is Microsoft SQL Operations Studio?

Read here: Microsoft SQL Operations Studio User Interface

Watch this video: Connecting to SQL Server 2016 Developer edition database using
Microsoft SQL Operations Studio


Install the latest MySQL and improve security

The latest MySql Version now presently as of Oct 15, 2024 is 8.4.3 , which was released as an LTS (Long Term Support) version:  These are th...