Saturday 21 March 2020

Discontinous Transmission

I will temporarily reduce the frequency of posts on this blog. The reasons are both on macro and micro scale.

We're in the middle of a move to a house in Åkarp. This project takes quite some time. Once we have moved, we need to learn about the house, explore the surroundings and get involved in the local community.

On a larger scale, escalating numbers of Covid-19 cases will have some impact for me:

  • The Disease - Probably low risk for me and my family, since we are not in the vulnerable demographic groups. But we have relatives that are.
  • Disruptions -  Several countries has introduced travel bans and quarantines for large populations. 
  • My work place has encouraged me and my colleagues to work from home. Schools and kindergartens are still open but this may is likely to change. 
  • Increased demand for some supplies has temporarily emptied shelves.
  • Financial Markets - the stock market and oil price has collapsed. 


I need to focus on all this for a (hopefully) short period of time. I'll post again when we've moved and things has calmed down a little.

Saturday 7 March 2020

StockAnalyzer: Enabling SQL Server Locally and Accessing it From Python

I've had some challenges when attempting to connect a NodeJS app to a MS SQL database on my computer. To trouble-shoot, I'll start with connecting a python script instead to a database.


  1. First, I need to make sure that the SQL server  is up and running.
  2. After that, I'll test the connection using Python or an UDL file.
  3. If that works, I'll connect using NodeJS
Step 1: SQL Server
From the app Sql Server Configuration Manager, SQL Server is running on my machine.
SQL Server Browser isn't active however. That app provides information about SQL resources and SQL server instances on this computer. It listens to UDP port 1434 and allows several different SQL Server instances on the same port.

If TCP/IP is enabled for  a SQL server, that server is assigned to a port. In addition, it is possible to make the server listen to a specific pipe. 

SQL Server reads out all active instances of the computer and notes their corresponding ports and pipes.

It is possible to reach SQL servers without the SQL Server Browser running on the host, but then the port (and pipe) needs to be specified. It may be necessary to open up a couple of ports in the firewall, such as 1433 and 1434.

First Attempt to Connect to SQL Server Using Python:

The script can't find the SQL server.
Second Attempt to Connect to SQL Server Using Python:

Now, the script can find the SQL server but it can't find the data source.
Now, the script seems to have come a bit further. It doesn't complain about not finding SQL Server anymore. Instead, it says that it can't find the data source. The reason is most likely because I've specified the wrong version of ODBC Driver. 

Third Attempt to Connect to SQL Server Using Python: 
This time I'll specify the actual version of SQL driver: 17.

Yay!

Now, I know that the SQL Server is up and running on my local computer, and I know how to access it from Python. The next step is to connect using a NodeJS script. I'll explore that in the next blog post.