python异常值处理实例_python-异常值:(“ 08001”,“ [08001] [unixODBC]...

我正在使用pyodbc库从ubuntu Vm上运行的python djanog Web应用程序连接到Windows上sql服务器的远程实例.

我有一个数据库连接类,如下所示,该类在尝试创建对象连接的行上中断(我一直在尝试许多connectionStrings);

import pyodbc

class SQLSeverConnection():

def __init__(self, DSN, user, password, database):

connectionString = 'DSN=MSSQLServerDataSource;UID=django;PWD=password123!;DATABASE=HD'

self.connection = pyodbc.connect(connectionString)

self.cursor = self.connection.cursor()

def getTableNames(self):

self.cursor.execute('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = \'BASE TABLE\'')

tables = self.cursor.fetchall()

return tables

def getColumnTitles(self, tableName):

self.cursor.execute("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "' ORDER BY ORDINAL_POSITION")

columns = self.cursor.fetchall()

return columns

def getColumnData(self, columnName, tableName, startDateTime, endDateTime):

self.cursor.execute('SELECT ' + columnName + ' FROM ' + tableName + ' BETWEEN ' + startDateTime + ' AND ' + endDateTime + ' ORDER BY timestamp')

data = self.cursor.fetchall()

return data

当我运行服务器时,出现标题中所述的错误.

我的配置文件如下:

(odbc.ini)

[MSSQLServerDataSource]

Driver = FreeTDS

Description = ODBC connection via FreeTDS

Trace = No

Servername = MSSQLServer

Database = HD

TDS_Version = 8.0

(odbcinst.ini)

[FreeTDS]

Description = TDS driver (Sybase/MS SQL)

# Some installations may differ in the paths

#Driver = /usr/lib/odbc/libtdsodbc.so

#Setup = /usr/lib/odbc/libtdsS.so

Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so

Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

CPTimeout =

CPReuse =

FileUsage = 4

(freetds.conf)

# $Id: freetds.conf,v 1.12 2007/12/25 06:02:36 jklowden Exp $

#

# This file is installed by FreeTDS if no file by the same

# name is found in the installation directory.

#

# For information about the layout of this file and its settings,

# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database

# server specific section

[global]

# TDS protocol version

; tds version = 4.2

# Whether to write a TDSDUMP file for diagnostic purposes

# (setting this to /tmp is insecure on a multi-user system)

; dump file = /tmp/freetds.log

; debug flags = 0xffff

# Command and connection timeouts

; timeout = 10

; connect timeout = 10

# If you get out-of-memory errors, it may mean that your client

# is trying to allocate a huge buffer for a TEXT field.

# Try setting 'text size' to a more reasonable limit

text size = 64512

#Server For Django App

[MSSQLSever]

host =

port = 1433

tds version = 8.0

当我在终端中输入odbcinst -j时;

unixODBC 2.2.14

DRIVERS............: /etc/odbcinst.ini

SYSTEM DATA SOURCES: /etc/odbc.ini

FILE DATA SOURCES..: /etc/ODBCDataSources

USER DATA SOURCES..: /home/user/.odbc.ini

SQLULEN Size.......: 8

SQLLEN Size........: 8

SQLSETPOSIROW Size.: 8

使用isql和dsn,用户和密码从命令行成功连接.

我真的不知道该怎么办,我已经忙了整整一天了.一些帮助将不胜感激!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值