Can I query Microsoft SQL Server using pure Python? - python

I need to query SQL Server from Python in a machine that I don't have admin rights. I can't install drivers in it. I'll query mainly from a Linux machine, but it would be nice if I it can also be used from Windows during development.
I want to make a simple query in MS SQL Server with a Python lib. A lib that doesn't need any driver installed in the Operating System. Is it possible? Everything that I found asks to install the Microsoft driver in the host OS.

A quick search turns up pydts but it's not supported by Microsoft and I have no idea how widely adopted it is or if it's being actively maintained. Here's the GitHub repo.

Related

Sybase ASE Client Tools for Windows and Linux

I am looking for Sybase ASE client tools for Windows and Linux. I am trying to access the database using isql. But in order to use isql in python, one must have the Sybase ASE drivers/client tools installed.
The server my code (python) will be running is Linux, and my development machine is Windows, so I need driver/client tools for both environment
If you go to this SAP download link and search the page for Adaptive Server Enterprise you'll find several links for the ASE SDK.
NOTE: all of the links are for recent versions of the ASE 16.0 product; these should be backward compatible with older versions of ASE (eg, in case you're connecting to ASE 15.7)
Click on the appropriate link, provide the obligatory 'registration' details and you're provided with a copy of the ASE SDK package.
While the page does mention trial downloads, I've never found the ASE SDK to be limited by any licensing requirements.

How do I connect to Oracle Exadata from Python?

I have tried connecting exadata from python using cx_Oracle, but faced issue stating
cx_Oracle.DatabaseError: DPI - 1047: Cannot locate a 64bit Oracle client library.
I am trying to install a 64bit cx_Oracle, but I need to know can I connect from python to exadata.
Follow the cx_Oracle Linux installation instructions. The piece you are missing is access to Oracle Client libraries. As noted in the other answer, using Instant Client is the way to go. You'll need the "Basic" or "Basic Light" package for Linux x86-64. If you don't know your character set requirement, then use "Basic". You can use the latest 19c version. This will let you connect to Oracle DB 11.2 and newer.
If you have root access (?) you may find the RPM packages easier. If you want to use ZIP files, unzip the package, set your LD_LIBRARY_PATH environment variable to the directory, and run Python.
In your cx_Oracle scripts you use the same database credentials and connection string that you would use in SQL*Plus.
Welcome to Stack Overflow!
For the record, Oracle Exadata is a platform consisting of hardware and software designed for extreme Oracle Database performance. cx_Oracle is the Python client library to operate on an Oracle Database - hence you want to connect to an Oracle Database utilizing the Python programming language.
cx_Oracle depends on OCI (Oracle Call Interface). You need to download and install Oracle Client Library on your workstation before you can do import cx_Oracle from within Python.
You will find the Oracle Client Library here
Best of luck!

How to connect to remote MS SQL Server from python using py(py)odbc

I have a remote ms sql server at office location and I wanted to connect from an ubuntu desktop to it. I installed DBeaver http://dbeaver.jkiss.org/ and it was working like a charm without any other dependency.
After this I started to setup a connection from python with no success until I found a straightforward tutorial at https://tryolabs.com/blog/2012/06/25/connecting-sql-server-database-python-under-ubuntu/. But this solution involved installing some packages to ubuntu itself and configuring some related config files in the system.
The question is if there is some python package to use without os dependencies?
I don't think you would be able to achieve what you want without installing some packages. Reason being you are connecting to the MSSQL which follows a different set of rules as it is from Microsoft.
If you were connecting to any DB (MySQL,MongoDB etc) you still need to install a package or module to make it work.
Try to install the package as described in the tutorial from the like you shared and if you run into any problem paste the problem here.

How to connect to a SQL Server database in Anaconda

I'm quite new to Python and programming in general, so please bear with me. At my work I have Anaconda (Python vers 2.7) installed and would like to connect to a Microsoft SQL Server database, preferably with ODBC. Related to this task I have a number of questions:
Is it correct that I cannot connect to a SQL Server database using sqlite3 or sqlalchemy? That I need a module like pyodbc? A brief explanation of why this is the case would be much appreciated.
EDIT: Question related to installation of pyodbc in anaconda removed, since I figured this out (by reading Cannot Install Python Modules after Installing Anaconda)
Help is much appreciated! If any of my questions/any other specifics need to be cleared up, please don't hesitate to ask. Thanks
I do not use Anaconda, but I use various databases and ODBC. At first you can try if you have odbc module installed. It is a part of pywin32 package (http://sourceforge.net/projects/pywin32/files/) and is packed with ActiveState Python distribution. Other distribution can install it separately. Simply try:
import odbc
db = odbc.odbc('dsn/user/password')
You can also try with pyodbc you mentioned in question. There is precompiled version for Windows and I think it will work with your Anaconda environment. After installing try:
import pyodbc
db = pyodbc.connect('Driver={SQL Server Native Client 10.0};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;')
You can find more connection strings at http://www.connectionstrings.com/
EDIT:
It seems that you have problem with bitness of ODBC driver.
Try to run this program to see what sources are visible to ODBC manager:
import odbc
source = odbc.SQLDataSources(odbc.SQL_FETCH_FIRST)
while source:
print(source)
source = odbc.SQLDataSources(odbc.SQL_FETCH_NEXT)

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access.
I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first.
The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using:
DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password')
Can Python do the same without installing cx_oracle and the Oracle client? Or are there any suggestions about how to write a module myself to do the same thing?
Thanks in advance!
An excerpt from https://forum.omz-software.com/topic/184/oracle-database:
There's no pure python client for Oracle and likely never will be. Even wonderful third-party toolsets like SQLalchemy still rely on cx_Oracle underneath to do the actual communication to the Oracle database servers.
—also, deciding by Google, the answer is no: there do not seem to be any pure Python Oracle clients in existence as of today.
Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:
ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora
I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.
if you don't want use cx_Oracle you should use expect scripting. ( for python pexpect). But you need to be carefully for handle all expectations.

Categories