I want to get in a good habit of recording some simple tutorials from time to time using the English language, so here comes the first one about my experience with running the SQL Server on Linux. Enjoy!





The first thing you need to do is to open the following website and follow the selected installation guide. For example, I’m using the ElementaryOS so I chose the Ubuntu guide. Also, make sure you’ll install the SQL Server Tools.

Eventually, you can open the Connect and Query tab and run the following command in your terminal:

sqlcmd -S localhost -U SA -P 'SECRET_PASSWORD' 1 sqlcmd - S localhost - U SA - P 'SECRET_PASSWORD'

You can execute a very simple query in order to make sure that everything works properly.

SELECT Name from sys.Databases; GO 1 2 SELECT Name from sys . Databases ; GO

From that point, you can go scroll down where I describe how to create a simple C# application, but if you’re using Visual Studio Code, most likely you will find the mssql extension to be the interesting tool.

Here you can find a quite comprehensive guide but as I shown in the video above it’s very easy to connect to the SQL Server instance using VS Code – just hit CTRL+SHIFT+P, create a new profile, type in “localhost” as the instance name, provide credentials and you’ll be connected to the SQL Server. From that point, you can execute a query by hitting the CTRL+SHIFT+E combination. There is also a lot of the useful SQL snippets – just start typing sql in the new SQL file created within a VS Code and you’ll see them popping out of nowhere.

And finally, in order to connect to the SQL Server, you can use a library like Dapper, just create a new C# .NET Core application, and type in the following code:

using System; using System.Data.SqlClient; using Dapper; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { using(var connection = new SqlConnection("Server=localhost;User Id=SA; Password=SECRET_PASSWORD;")) { var names = connection.Query<dynamic>("select name from sys.Databases;"); foreach(var name in names) { Console.WriteLine(name); } } } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 using System ; using System . Data . SqlClient ; using Dapper ; namespace ConsoleApplication { public class Program { public static void Main ( string [ ] args ) { using ( var connection = new SqlConnection ( "Server=localhost;User Id=SA; Password=SECRET_PASSWORD;" ) ) { var names = connection . Query < dynamic > ( "select name from sys.Databases;" ) ; foreach ( var name in names ) { Console . WriteLine ( name ) ; } } } } }

You can download this very simple application by clicking here.