pyodbc

Text inserted into Hyperlink field shows up but does not act as a link

三世轮回 提交于 2019-12-24 04:23:14
问题 I'm having difficulty getting my pyodbc inserted hyperlinks to work in my Access 2003 database. It appears to look like a hyperlink but does nothing when clicked on. For it to work, I have to edit it in Access and only then does it recognize that, "oh yeah that is a hyperlink". import pyodbc cnxn = pyodbc.connect("DRIVER={Microsoft Access Driver (*.mdb)};DBQ= C:\\Users\\multidata\\Documents\\db1.mdb;") cur = cnxn.cursor() #hyperlink is the text file. table1 is hyperlink column in ms access

sql server return value with pyodbc

一世执手 提交于 2019-12-24 03:50:12
问题 I am trying to run some stored proc with pyodbc and get the single return value using following code: conn = pyodbc.connect("driver={SQL Server};server=MyServer;database=MyDB;trusted_connection=true") cursor = conn.cursor() SQL_command = """ DECLARE @ret INT EXEC @ret = [dbo].proc_mySP @group= 0 , @description =? SELECT @ret """ cursor.execute(SQL_command, description) retValue = cursor.fetchall() And the framework of the stored proc is as follows: -- SOME CODE -- ...... -- EXEC another_sp --

pyodbc - read primary keys from MS Access (MDB) database

不羁的心 提交于 2019-12-24 02:04:12
问题 When I try to use cursor.primaryKeys("tablename") then exception occurs: Error: ('IM001', '[IM001] [Microsoft][ODBC Driver Manager] Driver does not support this function (0) (SQLPrimaryKeys)') list(cursor.columns(table='tablename')) does not reveal primary keys either. 回答1: For Access ODBC we can get the Primary Key columns via the .statistics method of the pyodbc cursor object: crsr = conn.cursor() table_name = 'MyTable' # dict comprehension: {ordinal_position: col_name} pk_cols = {row[7]:

Python open Microsoft SQL Server MDF file

我是研究僧i 提交于 2019-12-24 00:59:53
问题 How can I open an Microsoft SQL Server MDF file in Python? Edit I've tried pyodbc.connect but that requires a legitimate "server connection"—you can't simply open the MDF file— pyodbc.connect(driver='{SQL Server}', dbq=r'c:\database.mdf') (Like you'd do for MDB files.) pyodbc.Error: Neither DSN or SERVER keyword supplied Okay— pyodbc.connect(driver='{SQL Server}', dsn=r'c:\database.mdf') pyodbc.Error: Data source name not found All I want to do is list its schema and then it. 回答1: The fact

Readonly connection with mssql and pyodbc

你说的曾经没有我的故事 提交于 2019-12-23 20:23:24
问题 I'm having some trouble with trying to create a read-only connection and not sure if it's a bug or my error. Pyodbc's documentation indicates that it is possible to create a readonly connection. See https://mkleehammer.github.io/pyodbc/api-module.html When running the following though I receive no errors and it runs as if the READONLY keyword was not present at all (the update goes through). import pyodbc readonly_conn_str = "DRIVER={SQL Server Native Client 10.0};SERVER=...;DATABASE=...;UID=

Removing on the basis of condition

£可爱£侵袭症+ 提交于 2019-12-23 19:12:27
问题 I was trying to create a query loop, which does interactive steps from one instance to the next. After fetching the right data I have connected it with database I am able to run but I want to apply the cases on basis of datypes that if the COL_NAMES datatype is varchar then '' and if the COL_NAME datatype is float or int then replace it with 0 and for datetime datatye replace it with 1880-10-10 now I am able to apply only on blank on datatypes: a = ','.join(f"[{y}]=isnull([{y}], '')" for y in

sqlalchemy, specify database name with DSN

情到浓时终转凉″ 提交于 2019-12-23 17:31:50
问题 I am trying to connect to a SQL Server from Linux using sqlalchemy . This page shows DSN-based connection as below. engine = create_engine("mssql+pyodbc://scott:tiger@some_dsn") Is there a way to specify a database name using DSN? I am aware that we can specify a database name either in odbc.ini or a SQL query but I would like to know if we can also do something like this. engine = create_engine("mssql+pyodbc://scott:tiger@some_dsn/databasename") 回答1: You can pass arguments directly to the

Python - Can't open lib 'libtdsodbc.so' : file not found

心已入冬 提交于 2019-12-23 12:52:38
问题 Any help with this issue is much appreciated. Goal: Connect Django to MSSQL server using FreeTDS. I'm using a Debian x64 box. Problem: When trying to make a connection I get the following. ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'libtdsodbc.so' : file not found (0) (SQLDriverConnect)") My /etc/odbcinst.ini is configured as followed [FreeTDS] Description = FreeTDS driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so The

Python Pandas read_sql_query “'NoneType' object is not iterable” error

浪尽此生 提交于 2019-12-23 09:51:39
问题 I am trying to execute a sql and save a result into Panda Dataframe. here is my code. dbserver = 'validserver' filename = 'myquery.sql' database ='validdb' conn = pyodbc.connect(r'Driver={SQL Server};Server=' + dbserver + ';Database=' + database + ';Trusted_Connection=yes;') fd = open(filename, 'r') resultingData = pd.read_sql_query(fd.read(),conn) fd.close() conn.close() line pd.read_sql_query(fd.read(),conn) continues to give me error 'NoneType' object is not iterable” error I can run

pyodbc returns SQL Server DATE fields as strings

穿精又带淫゛_ 提交于 2019-12-23 09:41:30
问题 I'm using pyodbc to query a SQL Server 2008 database table with columns of DATE type. The resulting rows of data contain date strings rather than python datetime.date or datetime.datetime instances. This only appears to be an issue for columns of type DATE; columns of type DATETIME are handled correctly and return a datetime.datetime instance. Example import pyodbc from pprint import pformat db = pyodbc.connect("DRIVER={SQL Server};SERVER=.\\SQLEXPRESS;DATABASE=scratch;Trusted_Connection=yes"