trouble with win32serviceutil

2005-06-23 Thread Erik Myllymaki
I am trying to start and stop a service with python. This used to work on an NT 
box but not on this 2003 server machine. (note- using "net stop myService" and 
net start myService" from the command line works just fine). The event viewer 
does tell me that a "Start command was sent to myService" but the service never 
starts.

-

import win32serviceutil

def service_control(service,action,machine='192.168.1.9'):
 if action == 'stop':
 try:
 win32serviceutil.StopService(service, machine)
 return('%s stopped successfully' % service)
 except:
 return ("Error stopping %s" % (service))
 elif action == 'start':
 try:
 win32serviceutil.StartService(service, machine)
 return('%s started successfully' % service)
 except:
 return ("Error starting %s" % (service))
 elif action == 'restart':
 try:
 win32serviceutil.RestartService(service, machine)
 return('%s restarted successfully' % service)
 except:
 return ("Error restarting %s" % (service))
 elif action == 'status':
 if win32serviceutil.QueryServiceStatus(service, machine)[1] == 4:
 return("%s is running normally" % service)
 else:
 return("%s is *not* running" % service)


if __name__ == '__main__':
 machine = '192.168.1.9'
 service = 'myService'
 action = 'start'
 printservice_control(service,action,machine)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: trouble with win32serviceutil

2005-06-24 Thread Erik Myllymaki
Erik Myllymaki wrote:
> I am trying to start and stop a service with python. This used to work 
> on an NT box but not on this 2003 server machine. (note- using "net stop 
> myService" and net start myService" from the command line works just 
> fine). The event viewer does tell me that a "Start command was sent to 
> myService" but the service never starts.
> 
> -
> 
> import win32serviceutil
> 
> def service_control(service,action,machine='192.168.1.9'):
> if action == 'stop':
> try:
> win32serviceutil.StopService(service, machine)
> return('%s stopped successfully' % service)
> except:
> return ("Error stopping %s" % (service))
> elif action == 'start':
> try:
> win32serviceutil.StartService(service, machine)
> return('%s started successfully' % service)
> except:
> return ("Error starting %s" % (service))
> elif action == 'restart':
> try:
> win32serviceutil.RestartService(service, machine)
> return('%s restarted successfully' % service)
> except:
> return ("Error restarting %s" % (service))
> elif action == 'status':
> if win32serviceutil.QueryServiceStatus(service, machine)[1] == 4:
> return("%s is running normally" % service)
> else:
> return("%s is *not* running" % service)
> 
> 
> if __name__ == '__main__':
> machine = '192.168.1.9'
> service = 'myService'
> action = 'start'
> printservice_control(service,action,machine)

Answering my own question - seems to work i you do not specify machine name:

win32serviceutil.StartService(service)

instead of

win32serviceutil.StartService(service, machine)
-- 
http://mail.python.org/mailman/listinfo/python-list


trouble with mxODBC, unixODBC and MSSQL

2006-04-01 Thread erik . myllymaki
I am using a script that's worked for me in the past on Windows, but
now that i've moved it to a Linux machine it is not. The trouble seems
to be when trying to insert escaped characters into a  varchar field
(\n \r ,etc.).

-
# conn = mx.ODBC.WINDOWS.DriverConnect('DSN=myDSN;UID=sa;PWD=pwd')

conn = mx.ODBC.unixODBC.DriverConnect('DSN=myDSN;UID=sa;PWD=pwd')
curr = conn.cursor()

# These strings do not work:
# mystring = "Some text \n and some other text"
# mystring = "Some text \t and some other text"
# mystring = """Some text
and some other text"""

# This tring works just fine:
mystring = "Some text and some other text"


sql_insert = "insert into DEV..msg(message_id,body) values(?,?)"

curr.execute(sql_insert, (1,mystring))
curr.close()
conn.commit()
-

Here's the error message:

Error Type: OperationalError
Error Value: ('', 8179, '[unixODBC][FreeTDS][SQL Server]Could not find
prepared statement with handle 0.', 6083)

Any ideas greatly appreciated.

-- 
http://mail.python.org/mailman/listinfo/python-list