user3032122
user3032122

Reputation: 11

extraction data from file.mdf using pyodbc

I have an application for managing pharmacies (just an example ) this application is developed so that it relates to a single pharmacy . This application map on a Micrsoft DBMS MSSDE

each pharmacy generates database file ( pharmacy.mdf , pharmacy_log.mdf )

So after getting these files from different pharmacies, I wrote a script to automate data extraction from these all files

As the application is running, the script do the following tasks: - Stops the server MSSQL server - copy the two files from folder files recover and paste them in the path of the application - Restart the server - exctract the desired data

the connection with the database in question is using the python pyodbc Module

Once the extraction is run at a certain time pyodbc crash

i gotte this error:

cursor.execute ('select * from Pha.dbo.table_test ') pyodbc.Error : ( '01000 ',' [ 01000 ] [ Microsoft] [ODBC SQL Server Driver] [ Shared Memory] ConnectionWrite ( ( send () ( 10054 ) ( SQLExecDirectW ) ')

i wrote this code for connection:

log = os.path.join(path,c,"SIC_log.ldf")
mdf = os.path.join(path,c,"SIC.mdf")
print(log)
print(mdf)
subprocess.call('net stop mssqlserver')
time.sleep(2)
os.system('copy "' + log + '" "' + MSSQL_DIR+'"')
os.system('copy "' + mdf + '" "' + MSSQL_DIR+'"')
time.sleep(2)
subprocess.call('net start mssqlserver')
time.sleep(2)


# Open a connection with the database
cnxn = pyodbc.connect('DSN=SIC_ODBC')
time.sleep(2)
extract_clo(cnxn, wb, ws)
cnxn.close()

Upvotes: 1

Views: 1231

Answers (0)

Related Questions