Home  >  Article  >  Database  >  python清除数据库错误日志

python清除数据库错误日志

WBOY
WBOYOriginal
2016-06-07 16:00:451044browse

# coding=gbk from encodings import gbk import re import sys import os import pyodbc import traceback import decimal #连接数据库 conn = pyodbc.connect(DRIVER={SQL Server};SERVER=192.168.1.43;DATABASE=master;UID=sa;PWD=passwd123!) # 获取curs

# coding=gbk
from encodings import gbk
import re
import sys
import os
import pyodbc
import traceback
import decimal

#连接数据库
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.1.43;DATABASE=master;UID=sa;PWD=passwd123!')

# 获取cursor对象来进行操作
cursor = conn.cursor()

#清除错误日志
#query="select username,userid from dbo.tbluser where username='%s'" %(uname)
query="EXEC sys.sp_cycle_errorlog"
cursor.execute(query)
conn.commit

data=cursor.nextset()

while not data:
print ('清除43错误日志完成!')
break

#清除代理日志
#query="select username,userid from dbo.tbluser where username='%s'" %(uname)
query1="EXEC msdb.dbo.sp_cycle_agent_errorlog"
cursor.execute(query1)
conn.commit

data1=cursor.nextset()

while not data1:
print ('清除43代理日志完成!')
break
#关闭连接,释放资源

cursor.close()
conn.close()

com3='pause'
os.system(com3)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn