473,785 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server stored prcedures with output parameters

Has anyone, with any driver whatsoever, managed to retrieve output
parameters from a SQL Server stored procedure? I've just been rather
embarrassed to find out it's not as easy as it might seem, and people
are saying bad things about Python as a result :-(

mx.ODBC, which I regard as a highly-capable module, does not support the
callproc() API, and suggests use of the ODBC call format. It has caveats
in (some of) the documentation implying that output parameters cannot be
handled due to their indeterminate memory requirements, however.

The adodbapi module does have a stored procedure call in its unit tests,
and manages to pass that test, but when I call my own stored procedure
(which retrieves columns into the output parameters rather than using
SET to establish their values) I get back whatever value I supplied as
the output parameter rather than what the stored procedure is returning.

So, can anyone help me to fulfill what must be a very common database
requirement?

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #1
5 8306
Steve Holden wrote:
Has anyone, with any driver whatsoever, managed to retrieve output
parameters from a SQL Server stored procedure? I've just been rather
embarrassed to find out it's not as easy as it might seem, and people
are saying bad things about Python as a result :-(

mx.ODBC, which I regard as a highly-capable module, does not support the
callproc() API, and suggests use of the ODBC call format. It has caveats
in (some of) the documentation implying that output parameters cannot be
handled due to their indeterminate memory requirements, however.

The adodbapi module does have a stored procedure call in its unit tests,
and manages to pass that test, but when I call my own stored procedure
(which retrieves columns into the output parameters rather than using
SET to establish their values) I get back whatever value I supplied as
the output parameter rather than what the stored procedure is returning.

So, can anyone help me to fulfill what must be a very common database
requirement?

regards
Steve


Hmmm, following up, added another test to adodbapi to retrieve a value
from a table into an output parameter it works, so this puts the
suspicion on to the stored procedure. Since this was written by the
client I'll take a look at it later (when I'm back in the office) and
see what the problem might be.

happily-talking-away-to-myself-ly y'rs - steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #2
Steve Holden wrote:

Hmmm, following up, added another test to adodbapi to retrieve a value
from a table into an output parameter it works, so this puts the
suspicion on to the stored procedure. Since this was written by the
client I'll take a look at it later (when I'm back in the office) and
see what the problem might be.

happily-talking-away-to-myself-ly y'rs - steve


However, the stored procedure below appears to consistently return zero
for the link_id when called with:

columnist_id, url, title, description, link_id = \
curs.callproc(" sp_InsertArticl e",
(columnist_id, url, title, description, 0))

so maybe there really *is* something wrong. Or, hopefully, I'm just
making a simple mistake in the calls? Whatever value is used as the
fifth (output) parameter seems to get returned, despite the apparent
change in the stored procedure.

Create PROCEDURE dbo.sp_InsertAr ticle
(
@columnist_id int,
@url varchar(255),
@title varchar(99),
@description text,
@link_id int OUTPUT
)
AS
BEGIN
INSERT INTO link (columnist_id,u rl,title,descri ption)
VALUES (@columnist_id, @url,@title,@de scription)

SELECT @link_id = @@IDENTITY
END

GO

not-quite-so-happi-ly y'rs - steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #3
In article <HHWmd.10924$nj .1324@lakeread0 1>,
Steve Holden <st***@holdenwe b.com> wrote:

Has anyone, with any driver whatsoever, managed to retrieve output
parameters from a SQL Server stored procedure? I've just been rather
embarrassed to find out it's not as easy as it might seem, and people
are saying bad things about Python as a result :-(

mx.ODBC, which I regard as a highly-capable module, does not support
the callproc() API, and suggests use of the ODBC call format. It has
caveats in (some of) the documentation implying that output parameters
cannot be handled due to their indeterminate memory requirements,
however.


Keep in mind that it's been several years since I used Python with SQL
Server and about all I remember is that we used stored procedures
heavily with no problems. I have no clue whether we tried using stored
procedures with output parameters, but I wonder why you can't just use a
SELECT to call the stored procedure and return the values. Or at least
right another stored proc that does something roughly similar.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

WiFi is the SCSI of the 21st Century -- there are fundamental technical
reasons for sacrificing a goat. (with no apologies to John Woods)
Jul 18 '05 #4
In article <cn**********@p anix1.panix.com >, Aahz <aa**@pythoncra ft.com> wrote:

Keep in mind that it's been several years since I used Python with SQL
Server and about all I remember is that we used stored procedures
heavily with no problems. I have no clue whether we tried using stored
procedures with output parameters, but I wonder why you can't just use a
SELECT to call the stored procedure and return the values. Or at least
right another stored proc that does something roughly similar.


s/right/write/, but you knew that.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

WiFi is the SCSI of the 21st Century -- there are fundamental technical
reasons for sacrificing a goat. (with no apologies to John Woods)
Jul 18 '05 #5
Steve Holden <st***@holdenwe b.com> wrote in message news:<oSYmd.109 31$nj.6308@lake read01>...
Steve Holden wrote:

Hmmm, following up, added another test to adodbapi to retrieve a value
from a table into an output parameter it works, so this puts the
suspicion on to the stored procedure. Since this was written by the
client I'll take a look at it later (when I'm back in the office) and
see what the problem might be.

happily-talking-away-to-myself-ly y'rs - steve


However, the stored procedure below appears to consistently return zero
for the link_id when called with:

columnist_id, url, title, description, link_id = \
curs.callproc(" sp_InsertArticl e",
(columnist_id, url, title, description, 0))

so maybe there really *is* something wrong. Or, hopefully, I'm just
making a simple mistake in the calls? Whatever value is used as the
fifth (output) parameter seems to get returned, despite the apparent
change in the stored procedure.

Create PROCEDURE dbo.sp_InsertAr ticle
(
@columnist_id int,
@url varchar(255),
@title varchar(99),
@description text,
@link_id int OUTPUT
)
AS
BEGIN
INSERT INTO link (columnist_id,u rl,title,descri ption)
VALUES (@columnist_id, @url,@title,@de scription)

SELECT @link_id = @@IDENTITY
END

GO


I had a similar problem doing this once before that I think was
related to the connection string. Changing to use the SQLOLEDB
provider solved it. I've just tested the below script here and got
the expected results:

Stored procedure:

CREATE PROCEDURE TestSP
@param INTEGER OUTPUT
AS
BEGIN
select @param = 10
END

Python test:

import adodbapi

server='localho st'
dbname='brian'
user='sa'
password=''

db=adodbapi.con nect('Provider= SQLOLEDB.1;Data Source=%s;Initi al
Catalog=%s;User ID=%s;Password= %s;'%(server, dbname,user,pas sword))
cur = db.cursor()
print cur.callproc('T estSP',(999,))
[10]

--
Brian
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2447
by: ivan divandelen | last post by:
Hi, How can i pass a parameter SQL stored Procedure from ASP pages
3
18610
by: Michael | last post by:
This one's really got me. I have a VB.NET (version 1.1.4322) project that provides an easy way to execute stored procedures on a generic level. When I run the code on computer A (running SQL Server 2000 version 08.00.0194) the code works great. However, computer B (running SQL Server 2000 version 08.00.0534) bombs when I try to execute the sproc saying 'Could not find stored procedure 'spmw_ReadByPage'. My thought process went as...
2
5459
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
5
4380
by: Mike L | last post by:
I'm able to connect to my stored procedure in my local database but not able to connect to my stored procedure in the remote database. I use several different UserID and Password that all should work. It also fails when I try a different SP on the remote server. All local SP work. I copy local SP to remote SQL but still can not connect to remote SP.
4
50416
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList varchar(7) output AS select @out_eList = ecuid from _organization where rccode = @in_rc GO
2
6967
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
2
4108
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
12
2261
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my office. The original code's backend is using the SQL Server 2000 and I am testing to use it on the Express edition. And I run into the following problem.
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.