Revision d939cd87-8995-4101-9141-e095e460c5c6 - Stack Overflow

**CONNECTION FROM WINDOWS TO MS SQL SERVER DATABASE:**

Here you have an example I use myself to connect to MS SQL database table with a Python script:

 import pyodbc
 server = 'ip_database_server'
 database = 'database_name'
 username = 'user_name'
 password = 'user_password'
 driver = '{SQL Server}' # Driver you need to connect to the database
 port = '1433'
 cnn = pyodbc.connect('DRIVER='+driver+';PORT=port;SERVER='+server+';PORT=1443;DATABASE='+database+';UID='+username+
 ';PWD='+password)
 cursor = cnn.cursor()

'**User**' and '**password**' and '**table_name**' are attibutes defined by the DB administrator, and he should give them to you. The **port** to connect to is also defined by the admin. If you are trying to connect from a Windows device to the DB, go to ODBC Data Source Administrator from **Windows**, and check if you have installed the **driver**: 

https://learn.microsoft.com/en-us/sql/odbc/admin/odbc-data-source-administrator

[![ODBC Data Source Admin in Windows][1]][1] 

The image is in spanish, but you only have to click on 'Drivers' tab, and check if the driver is there as in the image. 

**CONNECTION FROM LINUX/UNIX TO MS SQL SERVER DATABASE**

If you are working in **Linux/Unix**, then you shoud install a ODBC manager like '**FreeTDS**' and '**unixODBC**'. To configure them, you have some examples in the following links:

https://help.pythonanywhere.com/pages/MSSQLServer/

http://www.asteriskdocs.org/en/3rd_Edition/asterisk-book-html-chunk/installing_configuring_odbc.html




 [1]: https://i.sstatic.net/70CEC.png

AltStyle によって変換されたページ (->オリジナル) /