.Net Core on Mac: Connecting to SQLServer

In the previous post I described how I set the basic development environment using Visual Studio Code. You cannot do much application development without a database though, and while there are many options for database connectivity, since this exercise is  about using a Microsoft development stack on a Mac, the database of choice is inevitably Sqlserver.

When I started thinking about all these, the only option I had was to install Sqlserver on my Mac in a virtual machine. And this is what I did. I installed Virtualbox with  Windows 10 LTBS and in it, I installed Sqlserver. I won’t go through this process as it is not Mac related. The point of interest is the network connectivity for the Virtualbox: in order to be able to talk to the Sqlserver inside it, one needs to use bridged networking.

screen-shot-2016-11-26-at-7-34-10-pm

Also, since we are going to connect to Sqlserver through the network, TCP connectivity must be enabled.

screen-shot-2016-11-26-at-8-34-51-pm

To test the connectivity you can use command line tools, a Mac client like Navicat Essentials for SQL Server or connect directly through the Visual Studio Code.

There is an extension for this:  mssql for Visual Studio Code

Like all extensions in VSC it adds a bunch of commands

screen-shot-2016-11-26-at-8-42-55-pm

The extension works from within the editor: you open a document and change the language mode to SQL.

screen-shot-2016-11-26-at-9-04-23-pm

Then you create a connection profile and connect to the Virtualbox Sqlserver. Upon a successful connection the footer of VSC changes to this:

screen-shot-2016-11-26-at-8-48-15-pm

And now the party begins.

In the opened document you type sql commands and execute them running the Execute query command. The results are fetched in another document and the screen splits in two: sql on the left, data on the right.

Screen Shot 2016-11-26 at 8.52.57 PM.png

From this point on, you have all the tools in place to dive into some real development.

Except that…

connecting to a Virtualbox hosted Sqlserver is not the less resource hungry solution.

After I set the above, Microsoft made a lot a good announcements in the Connect() event. Among them was the release of Sqlserver for Mac though Docker, which promises a lighter solution. The docker container runs Ubuntu linux, so there is no real Sqlserver for Mac. Just a better workaround. But I will leave this for a future post.

.Net Core on a Mac: Setting the development environment

Let’s begin from the beginning: I installed  .Net Core SDK ,  Visual Studio Code (VSC) and the C# extension. The tricky part was the SDK which uses OpenSSL . I had  to install it  beforehand with Homebrew.

At this point a basic development environment is place. But since I didn’t want to develop a CLI application but an Asp .Net MVC one, and since VSC does not provide project scaffolding like it’s big brother, Visual Studio, I had to install yeoman for this task (another cli tool) a task that, requires Node.js so that you end up with npm and finally run

npm install -g yo generator-aspnet bower

(Yes, it has to have bower too).

And now, everything is ready to start a project. I run:

yo aspnet

and got

     _-----_     ╭──────────────────────────╮
    |       |    │      Welcome to the      │
    |--(o)--|    │  marvellous ASP.NET Core │
   `---------´   │        generator!        │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? What type of application do you want to create? (Use arrow keys)
❯ Empty Web Application 
  Empty Web Application (F#) 
  Console Application 
  Console Application (F#) 
  Web Application 
  Web Application Basic [without Membership and Authorization] 
  Web Application Basic [without Membership and Authorization] (F#)

I chose

 Web Application Basic [without Membership and Authorization]

and was good to go.

Or, was I?

Client side development encompasses tasks like building css from sass or less, bundling and minifying. I had to accommodate for these too. I decided for scss so I had to install sass.

gem install sass

(Has anyone been counting the package managers used so far? I will provide a count later).

And, per the .Net Core tutorials and documentation, I had to install gulp for sass compilation (and bundling/minification). Thank God, npm was already in place.

npm install --save-dev gulp

At this point I could open my newly created project (ok, the screenshot was taken later).

screen-shot-2016-11-16-at-8-06-30-pm

Database connectivity would have to wait a bit, until we get the basics straight.

The last piece I had to install was the C# extension. Yes, C# is not supported by default! You need to add it as an extension from within VSC.

VSC is mainly addressed to javascript developers, it seems.

So, to come here I have used the following package managers:

  • brew
  • npm
  • gem
  • bower
  • nuget (internally in VSC)

and two additional cli tools

  • yeoman
  • gulp

Unfortunately, after having done all the above, I found out that gulp will be discontinued in future releases (Bye, bye gulp).

And advancing a little bit with the configuration, I found also that the current project.json is going to be replaced by MSBuild (Bye, bye project.json).
Honestly, this gave me the creeps, not because I have any particular affection for either gulp or project.json but because it shows a fickleness of ‘heart’ towards the adopted affiliations. If one wants to adopt something new, the last thing he needs in uncertainty.

Having said that, it doesn’t seem to be a compromise on Microsoft’s newly developed commitment to openness, as, today, they announced joining the Linux foundation and they released Visual Studio for Mac (preview).

 

It’s been now quite a few days that I have been working with the current environment and apart from some annoyances that I will list below, I am rather happy, mostly because VSC is not just an editor. It has a lot of IDE capabilities, something that I have been missing to other lighter editors, or found too cumbersome to work with.

And since Intellisense is one of my main reasons for satisfaction, it is its shortfalls that frustrate me the most:

  • Version management in project.json is messy. Intellisense suggestions sometime are wrong (I got hints for version 2.0.0 and 3.0.0 where the package is still in 1.x.x), other times they do not show up at all.
  • Enabling Visual Studio Code Taghelpers did not help. Taghelpers Intellisense does not work. I posted a relevant question in Stackoverflow which, to the moment of writing, remains unanswered.
  • After correcting some misprints or wrong references in the code, there are artifacts left behind (red squiggly lines, underlining the problem that does not exist anymore). They go away with the first compilation though.

But with the current environment I have done a lot of progress in two areas: after creating the basic views and controllers, I spent a lot of time in route configuration and localization, which, I remind to those that haven’t read my previous post, is to migrate the company website from WordPress to Asp Net MVC.

.Net Core on a Mac

It’s been ages since I blogged anything. More, anything technical. Since I am in the process of experimenting with ASP .NET Core on my Mac, I thought to take the opportunity and log this journey here.

So far I have done three things:

This isn’t as straightforward as just installing Visual Studio Code. To have scaffolding one  needs to rely on CLI tools, and to do some client side development on the usual suspects: bower, jQuery, bootstrap etc. Which means you need to spend a lot of time  with the Terminal.

  • Set up a development database

While one can experiment with SQLite or MySQL, I wanted the real Microsoft thing, SQL Server, and since this isn’t available for Mac I used Virtual Box with a Windows 10 LTSB guest, where I installed SQL Server Express.

To connect to the database from the host, the VirtualBox has to be on bridged networking and SQL Server should be accepting TCP connections.

  • Found a relatively simple project that entails the most common workflows.

Our company’s website  is multilingual and it is WordPress based (no wonder). While the blog  parts serve their purpose nicely, the pages are bloated (HTML-wise) and have a lot of javascript code running (for a reason) which could benefit from a slimming diet.

So, I thought, why not try to migrate the WordPress pages (not the posts) to an MVC site based on Asp .Net Core. To make things more interesting, I want to add some dynamic content too, pulled from our app’s database (why should I be bothering with SQL Server if I didn’t?).

And here I am. So far, I have made some progress which I will relate in subsequent posts. This post is only an introduction to the theme. If you have interest in such experiments, stay tuned.

Why people stick to their views despite evidence to the contrary?

Why people stick to their views despite evidence to the contrary?

More, why do they stick to their views fanatically especially when there is evidence to the contrary?

From the little I have read on the subject, the explanation seems to lie in our perception of “self”. Our views are an essential part of what we perceive as our “self” and an attack on the views is considered as an attack on the “self”. Therefore, we counterattack.

To reinforce the sense of “self” we stick to like minded people, read and watch only what confirms our prejudices and revel on the trashing of the “opponents”.

This must be a “bug” of our mental apparatus. Because, in the course of time, we change views anyway. Only never when we are told so. So we change “self” and disprove the importance of having this specific view or the other.

But in the short term we consider our views as “eternal” because this serves well the “selfishness” of this plastic thing called “ the self”. Maybe this is what led Buddha to proclaim that the “self” is an illusion.

How do we fix this “bug”? This is an open question. My personal experience leads me to believe that it happens more easily in non-confrontational situations. More likely when you are reading a book, or watching a documentary, than when you are discussing with another person.

Which shifts the problem to “how one picks the right book/documentary/experience etc” that would help him to fix his views?

In essence, we never “pick”. Like the social media maxim goes, the “news” find us. And it is precisely into this modern space, the social media space, that it gets easier to pick up new views provided that they just “flow” around you and not directed at you. At least, I think so.

The productivity of illness

There Is A Light That Never Goes Out
It has happened to me a few times but it wash’t until today, the third day of being confined at home because of my flu, that I began to see the pattern.

Being sick is a great chance to think! 

“Oh, man, this is … sick”, you might say. Maybe, but it is true nevertheless. And there is a very good reason for this: you don’t have many alternatives.

What I mean is that if you are really sick, you probably are in bed, cannot do a lot of work, cannot see or talk to many people, watch tv, read books or surf the net. If you are really sick. Or you can do all of the above but for a limited amount of time. And the rest of the day you lie on your bed suffering and waiting.

But there is an organ  that is not too much affected by the condition of the rest of the body: the brain.

Yes, you might be sleepy or feel that your thought is misty, yet, in the absence of external preoccupations, and with plenty of idle time,  all your latent thoughts, worries, forgotten tasks, fears, hopes and desires will find a way to sneak into your consciousness. And here lies your moment of opportunity: you can play it like tv, i.e. watch and forget, or you can try to make some sense out of this mental jumble, discover things, short out other and finally, find inspiration and motivation to change your way onwards.

And this is precisely the pattern I realised today: it has happened to me each time I was in bed for more than one day. And each time I got away with something good. Not always significant or lasting, but, at least temporarily, beneficial.

As a matter of fact, this is how I came up with the Discoveroom idea. It was two years ago when I was in bed for about a month because of my waist. As a matter of fact, lots of ideas came to me then. I even had  a moleskine by me to note them down quickly. I also started learning ruby and embarked in a pet project utilising codeigniter. But the one thing that got stuck was Discoveroom (not by this name, or any name, in the beginning) and now that I am again in bed, this is the one I find myself deliberating about.

So, what’s the moral here? Get ill to get things done? Of course not. The moral is that there is no idle time. Only idle people. You choose what you are.

 

 

Working for a startup

A few days ago I commented on a post by Nikos  Moraitakis about why people should, of all things, want to work for a (greek) startup.  Today,  I read a post by Mike Greenfield, titled “Why Developers Aren’t Interested In Your Startup” which kind of reinforced my point of view.

First, here  is what I wrote in my comment, mildly edited.

Nikos, I think we should make understood, as emphatically as possible, that startups are VERY risky endeavors. They are not for the light hearted. And you do not want to lure the wrong people in them, as they will most probably quit on the first few obstacles. But attracting the wrong people  is a very probable turn of events in a crisis as the one we are undergoing in our country: you WILL lure them just because they have nothing else to do.

So, if the picture is as bleak as I am drawing it, how startups can ever find the right people to work for them?
There is a simple guiding principle here: economic behavior is about motives and the motive of a startup job is a reward substantially big to balance the high risk undertaken.
Having said that, I do not imply a financial reward necessarily, although this would be a strong motivator.
Since, by definition, startups do not have enough cash to pay big salaries, any kind of financial reward must have a variable element that relates to startup performance. Stock options is the most common such reward. This is the reason I had tried to open the discussion about stock options earlier this year.
Apart from the financial rewards, there are two other equally strong rewards:

  • do the things that you really really really like and are passionate about, and
  • learn a prodigiously lot of stuff in a very short time.

The first is not obvious. It concerns people with special skills that want to put them into work. If, for instance, someone has made studies in a very specialized area, it is not likely that he can put these studies to work anywhere else than in a startup. So if he really loves his field, he will be willing to undertake the hardships and the possibly less remuneration just to able to work on the thing he loves.

The second has to do with the multifaceted role that each employee plays in a startup. Actually, to be completely honest, there is no role. Not an exactly defined, at least. Especially in the very beginning.
It is, more or less, a broad direction that one gets, than a job description. Which means that he has to have the motive and the guts to pave his own way.

Greenfield’s findings support the view that financial rewards are one of the main motivators, although they appear fourth in the post. The other three are:

  • Industry
  • Founders’ reputation
  • Investors’ reputation

I relate also ‘industry’ to what I refer as ‘specialization’ for obvious reasons, and i tend to agree with Greenfield on his guess that working for a startup that potentially has the power to do social good or change the world in some aspect is also a big factor.

But apart from my beliefs and guesses it would be interesting to hear from others what would attract them to a startup despite the fact that they could possibly get a higher salary in a more mature company. What can counterbalance the financial rewards?

Mac et al. annoyances

The last few days I am under a spell of bad luck: a near the elbow left-arm fracture, an old spine hernia that came back with a vengeance, confining me to bed the past two days, and, today, a Macbook Air that refuses make a  sound  while it won’t let me end a dialog.

Since the health of the body is less important than the health of the mind Mac, I will skip the first and focus on the second🙂

I have a 4,5 year Mac book Air (first generation), with an 80Gb disk. I have managed to keep upgrading up to Snow Leopard and then stopped. I have decided that my next upgrade will be a new Mac book, not a new OSX for the current one.

In the short (or long, depending on the perspective) life of this machine I have experienced two serious problems, both taken care by Apple Support.

Before turning to apple support for this one too, I want to describe it here, hoping that someone might stumble on it and offer a solution that I haven’t already found (i.e.  tried, and rejected) googling for an answer.

Sound

The sound problem looks like  a hardware one. At least, this was my first impression since input and output devices ceased to show up in the Sound Settings in System Preferences.

The first search though, revealed that this is an all too common Mac problem, highly correlated to Air’s and Lions. So with an Air and no Lion I have a  50% chance of a software problem.

The known remedies to the missing sound problem, nicely summed up here, offered me no consolance. Neither the PRAM trick. So, I am afraid that it really is a hardware problem.

Image

Dialogs

The program I use most frequently (next to Chrome) is Coda, since I am doing most of my professional and personal work with it. But today it let me down too, although I don’t think it is strictly a Coda issue, as I noticed the same behavior with a couple of other programs too, namely Mail and SourceTree, but since I do not use them often I did not pay attention.

So what is this problem? Every time I attempt to open Coda I get stuck with the dialog below. I cannot close it, press a button, or make it progress. It stays there eternally.

Image

What the dialog says is true. I indeed got stuck saving a remote file, that forced to quit coda,  and since then…

My thought was that if I cleaned the local copies the dialog would disappear.

I tried to clear the cache but had problem finding it.

I deleted the Cache.db file in ~/Library/Caches/com.panic.Coda and all the entries in ~/Library/Coda/ (which look unrelated, but did it nevertheless). Then I looked at ~/Library/Application Support/Coda/Logs but the folder was empty.

In short, I did not find the cached remote files.

As a last resort, I also attempted to reinstall Coda. I got exactly the same result.

The funny thing is that if I click on a document that normally opens with Coda, the document opens nicely but then the accursed dialog kicks in.

So here I stand, or, rather, I lie, with no other solution left only than to beg you, kind reader, for one, before I make apple support richer.

Update 1: 

I managed to get rid of the annoying dialog by cleaning some cache files in /Library/Caches.  More specifically, after cleaning blindly all the cache files and folders that had a date close to yesterday, I opened Coda, saw the dialog again but this time clicking on cancel actually worked. Then, it asked me for a key, as I had reinstalled it and after putting the original purchase key, the confirmation dialog got stuck again. This time I knew where to look and it appeared that the only newly created cache file was /Library/Caches/com.apple.DiagnosticReporting.Networks.plist. I deleted it again, reopened Coda, repeated the above steps but this time, after entering the license key, the confirmation dialog worked. Of course all my setting were gone with the cache cleaning and reinstallation which is already a loss. But, at least I have Coda working.

Now, the property list file mentioned above, did not appear to have anything special inside. As a matter of fact, the one I initially deleted and the new one generated were identical. So, I cannot tell why it helped.

Update 2:

It took me sometime to make the connection: the two issues are related. In a very simple and stupid way: the dialogs get stuck as they attempt to play a sound. And since the sound system is dead, the dialog hangs up waiting. So, what I did, was disable the interface sound effects and, voila, dialogs started behaving.


Update 3 (7/12/2012)
Sigh! I was wrong. The dialogs problem is still there. And not only in Coda…

Xeni