ADO and Store Procedure
Joel Quinet
joel.quinet at be.unisys.com
Tue Mar 12 11:13:12 EST 2002
Hi everybody
I make some test with ADO and Python which run correctly now.
But I still have some little problem :
The following code call a stored procedure in SQL Server 7. This stored
procedure insert a row in a table.
There is a Unique Contsraint on that table. If I try to insert an existing
value in that table with the following script,
I receive no error ....
I would like to receive an error and be able to deale with it.
Moreover, My store procedure return 1 in case of problem. How can I rescue
that ?
How can I do that ?
PS : the stored procedure works well in SQL Interactif mode
Thanks
Joel
from win32com.client import constants
from win32com.client import gencache
mServer = '(local)'
mUsr = 'sa'
mPwd = ''
mDb = 'Test'
conn = win32com.client.Dispatch(r'ADODB.Connection')
DSN = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + mUsr +
";" + "Password=" + mPwd + ";Initial Catalog= " + mDb + " ; Data Source=" +
mServer + ""
err = win32com.client.Dispatch(r'ADODB.Error')
conn.Open(DSN)
cmd = win32com.client.Dispatch(r'ADODB.Command')
cmd.ActiveConnection = conn
cmd.CommandText = "Insert_Continent"
cmd.Prepared = 1
cmd.CommandType = constants.adCmdStoredProc
cmd.CommandTimeout = 15
prm = win32com.client.Dispatch(r'ADODB.Parameter')
prm.Type = constants.adChar
prm.Size = 6
prm.Direction = constants.adParamInput
prm.Value = 'Europe'
cmd.Parameters.Append(prm)
rs, res = cmd.Execute()
More information about the Python-list
mailing list