Dear all,
I'm trying to connect to the batch historian database by using pyodbc (Pyodbc is an open source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification. Using pyodbc, you can easily connect Python applications to data sources with an ODBC driver). But i am having trouble to connect to the database.
My code looks like this:
sql_conn = pyodbc.connect("ODBC Driver 17 for SQL Server};" "SERVER=server01;" "DATABASE=DVHisDB;" "Trusted_Connection=yes;")
but i keep getting the following error:
InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
I've tried connectin using the pyhon 32 bit as well as 64 bit and I get the same error for both version of python.
On the server side the driver seems to be installed. Do i have to configure a data source or is it automatically configured at installation of the Batch Historian?
Kind regards,
Jordi
In reply to Lun.Raznik:
Just tried using miniconda Python 3.8 64-bit, this dumps all the table/views under DVHisDB
In [11]: import pyodbc
In [12]: sql_conn = pyodbc.connect("Driver={SQL Server};SERVER=localhost;DATABASE=DVHisDB;Trusted_Connection=yes;")
In [13]: cursor = sql_conn.cursor()
In [14]: for row in cursor.tables(): ...: print(row.table_name)
In reply to LaurentB:
This is indeed the case,
DV version 14.3.1
I am trying to gather the data from outside of the domain and am getting login issues.
I'm getting the following error message: Error 28000: Login failed for user DOMAIN\\user with pyodbc.
So I'm now looking for a solution to this problem. I came across some solutions like>
pyodbc.connect('DRIVER={SQL Server};SERVER=server;DATABASE=database;UID=me;PWD=pass')
but i'm still getting the same error. Besides i dont like the idea of storing a password in the code.
I fount a solution sugesting I should run the code by using RUNAS, but i havent tried yet.
Regards,