Showing posts with label sql server. Show all posts
Showing posts with label sql server. Show all posts

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 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