1

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()
  • If you launch SQL Server Management Studio and `Attach...` the database files manually can you browse tables, run queries, etc. from in there? – Gord Thompson Jan 29 '14 at 17:39
  • Yes ! i can browse tables and run queries. – user3032122 Jan 29 '14 at 18:02
  • Okay, good. And if you manually stop the SQL Server, manually copy two different .mdf and .ldf files over existing ones, and then manually restart the SQL Server can you successfully access the database from SSMS? ...and from a simple Python script (that just opens and reads the database without the swapping stuff)? – Gord Thompson Jan 29 '14 at 18:14
  • Yes, I can do all the stuff you describe above. – user3032122 Jan 29 '14 at 20:40

0 Answers0