在Ubuntu Azure VM上找到SQL Server的ODBC驱动程序13.0 [英] Locating ODBC Driver 13.0 for SQL Server on Ubuntu Azure VM

查看:83
本文介绍了在Ubuntu Azure VM上找到SQL Server的ODBC驱动程序13.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python脚本,需要ODBC驱动程序13.1才能将SQL Server连接到SQL Server并写入SQL Server.我正在尝试在Azure上运行Ubuntu 16.04的Linux VM上设置脚本.我无法找到要在脚本中使用的驱动程序的位置.

I have a python script that requires ODBC Driver 13.1 for SQL Server to connect and write to a SQL Server. I am trying to setup the script on a Linux VM running Ubuntu 16.04 on Azure. I am having trouble locating the location of the driver to use in my script.

我已按照

I have followed the instructions here on installing ODBC and it appears to have installed successfully. However, whenever I look for where it has installed on my system, I cannot find it.

在我的本地计算机上,我将信息传递给连接字符串,如下所示:

On my local machine, I am passing the information to the connection string like so:

server = '{server name}'
username = '{username}'
password = '{password}'
driver = '/usr/local/lib/libmsodbcsql.13.dylib'

# use following string for database connection
con = sqlalchemy.create_engine('mssql+pyodbc://' + user + ':' + passw + '@' + host + ':' + str(port) + '/' + database + '?' + 'driver' + '=' + driver, echo=False

在Linux VM上,当我从Microsoft安装ODBC时,这是输出的一部分

On the Linux VM, when I installed ODBC from Microsoft this was a portion of the output

Preparing to unpack .../msodbcsql_13.1.9.2-1_amd64.deb ...
Unpacking msodbcsql (13.1.9.2-1) ...

该文件路径的其余部分在哪里?当我使用find . .../msodbcsql_13.1.9.2-1_amd64.deb时,没有返回结果

Where is the rest of that file path? When I used find . .../msodbcsql_13.1.9.2-1_amd64.deb it returned no results

为了使脚本起作用,我需要找到驱动程序在服务器上的位置,以便将该路径传递给脚本.

In order for the script to function, I need to locate where the driver is on the server so I can pass that path to the script.

推荐答案

首先,请确保已通过apt-get在Azure Ubuntu VM上安装了unixodbc-dev.然后sqlalchemy需要pymssqlpyodbc模块,您可以参考正式文档

First, please make sure that you have installed unixodbc-dev via apt-get on Azure Ubuntu VM. Then the pymssql or pyodbc module is required by sqlalchemy, you can refer to the offical document Python SQL Driver to install it.

接下来,我对SO线程 Microsoft Azure Data您可以参考的仓库和SqlAlchemy ,其中包括以下示例代码.

Next, there is my answer for the SO thread Microsoft Azure Data warehouse and SqlAlchemy which you can refer to, and it includes the sample codes as below.

import sqlalchemy

connection_string = "mssql+pyodbc://<user>@<server-host>:<password>@<server-host>.database.windows.net:1433/<database>?driver=ODBC+Driver+13+for+SQL+Server"
engine = sqlalchemy.engine.create_engine(connection_string)
engine.connect()

import sqlalchemy
import urllib

params = urllib.quote_plus("Driver={ODBC Driver 13 for SQL Server};Server=<server-host>.database.windows.net,1433;Database=<database>;Uid=<user>@<server-host>;Pwd=<password>;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;")
engine = sqlalchemy.engine.create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)
engine.connect()

有关带有pyodbcpymssqlsqlalchemy的更多详细信息,请参见 Microsoft SQL Server .

For more details about sqlalchemy with pyodbc or pymssql, please see the SQLAlchemy document for Microsoft SQL Server.

这篇关于在Ubuntu Azure VM上找到SQL Server的ODBC驱动程序13.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆