2016 12 Python Base Datos
2016 12 Python Base Datos
2016 12 Python Base Datos
linux
#Referencias
http://askubuntu.com/questions/578934/mssql-connection-from-ubuntu
/etc/odbcinst.ini
[FreeTDS]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
/etc/freetds/freetds.conf
# [Global]
#TDS_Version = 8.0
#client charset = UTF-8
host = xxxxxxx
port = xxxx
tds version = 8.0
#Procedimiento Centos 7 .
https://www.petri.com/how-to-connect-centos-web-server-to-a-sql-server
vi tds.driver.template
[FreeTDS]
Description = v0.91 with protocol v8.0
Driver = /usr/lib64/libtdsodbc.so.0
vi tds.datasource.template
##Configurar archivos
[DSNName]
Driver = FreeTDS
Description = TDS_Servername
Trace = No
Server = xxxxxx
Port = xxxxx
TDS Version = 8.0
Database = xxxx
# odbcinst -i -d -f tds.driver.template
odbcinst: Driver installed. Usage count increased to 1.
Target directory is /etc
# odbcinst -i -s -f tds.datasource.template
cp /root/.odbc.ini /etc/odbc.ini
import pypyodbc
conexion=pypyodbc.connect("Driver=FreeTDS;SERVER=xxxxx;port=xxx;UID=xxxxx;PWD=xxx
xxx;DATABASE=xxxxxx")
INSERTAR DATOS
cursor.execute("insert into RSAM(rsam_estacion,rsam_canal) values('BREF','BHZ')")
CONSULTAR DATOS
>>> cursor.execute("select * from RSAM")
<pypyodbc.Cursor instance at 0x1c28998>
>>>
>>> for fila in cursor:
... print fila
...
(1, 'BREF', 'BHZ', None, None, None, None, None, None)
(2, 'BREF', 'BHZ', None, None, None, None, None, None)
(3, 'BREF', 'BHZ', None, None, None, None, None, None)