Tuesday, December 17, 2019

Python3 connect to Microsof SQL Server

1. sudo apt-get install python3-pip
2. pip3 install pyodbc
3. sudo apt-get install unixodbc-dev
4. follow the Microsoft's documentations (ref: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15 )
4.a
sudo su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - 4.b curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
4.c sudo apt-get update
4.d sudo apt-get install msodbcsql17


Test connection with this code:
import pyodbcconn = pyodbc.connect("Driver={ODBC Driver 17 for SQL Server};" "Server=SERVER_IP;" "Database=DB_NAME;" "uid=DB_USERNAME;pwd=DB_PASSWORD;")conn.close()


Some error maybe occured:
> ModuleNotFoundError: No module named 'pyodbc' --> solution: pip3 install pyodbc

> pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)") --> solution: sudo apt-get install msodbcsql17

* My machine ubuntu 18.04


Monday, December 16, 2019

How to start ubuntu in command line interface

I want to set my ubuntu PC to command line interface. I don't want to start the desktop manager.

1. Edit /etc/default/grub

2. Find this section:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
3. change to:
GRUB_CMDLINE_LINUX_DEFAULT="text"
GRUB_CMDLINE_LINUX="3"

 4. run: sudo update-grub

5. Done. Every time we start the PC, it doesn't start the desktop manager automatically. If we want to start the desktop manager, run: sudo init 5


* My machine ubuntu 18.04

Monday, December 9, 2019

Can not change table structure in SQL server management studio 2008

I got this error

"Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to re-created."



when trying to change my table structure.

The solution is go to : Tools - options - designer - unchecked Prevent saving changes that require table re-creation