[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Can't get my stored proc OUTPUT parameters to come back in my ASP.NET application

Posted on 2007-03-30
7
Medium Priority
?
247 Views
Last Modified: 2013-11-26
I'm unable to get my OUTPUT parameters to come back properly. I have ran my stored proc with the values I'm using in my app in query analyzer and it works fine. I'm going crazy.

-----------------------------------------------------------------------------------------

Dim myConnection As New SqlConnection("server=(local);database=uw_data;uid=jrmcintosh;pwd=ncr3170")
            myConnection.Open()

            Dim myCommand As New SqlCommand("usp_sel_getuser", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure
            Dim uwuser As New SqlParameter("@user", SqlDbType.VarChar, 1)
            uwuser.Value = txtEmail.Text
            myCommand.Parameters.Add(uwuser)
            Dim pass As New SqlParameter("@password", SqlDbType.VarChar, 1)
            pass.Value = txtPassword.Text
            myCommand.Parameters.Add(pass)
            Dim success As New SqlParameter("@success", SqlDbType.Int, 4)
            success.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(success)
            Dim userid As New SqlParameter("@userid", SqlDbType.VarChar, 1)
            userid.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(userid)
            myCommand.ExecuteNonQuery()

            Dim count As Int16 = success.Value
            Session("userid") = userid.Value

            lblcount.Text = count

            myConnection.Close()
0
Comment
Question by:jrmcintosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 11

Expert Comment

by:dready
ID: 18825401
Did you declarre the parameters as output in the stored procedure usp_sel_getuser ????
0
 

Author Comment

by:jrmcintosh
ID: 18825462
yes

CREATE PROCEDURE dbo.usp_sel_getuser

@user varchar(100),
@password varchar(100),
@success int OUTPUT,
@userid varchar(100) OUTPUT

AS

SELECT * from uw_users where userid = @user  AND pass = @password

SET @userid = (SELECT userid from uw_users where userid = @user AND pass = @password)

SET @success = (select COUNT(*) from uw_users where userid = @user AND pass = @password)

GO
0
 

Author Comment

by:jrmcintosh
ID: 18825467
This is my first time using this method of calling a stored procedure. I have been using the enterprise library method for the past year so this is new to me...
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 11

Expert Comment

by:dready
ID: 18825477
So, your stp should look something like

CREATE PROCEDURE usp_sel_getuser
@user varchar(50),   -- This is a input parameter.
@password varchar(50),
@success int OUTPUT,
@userid varchar OUTPUT
AS  
-- here you do something.

Also, I am  not sure wetheryou set the length of your params correctly in the VB code
0
 

Author Comment

by:jrmcintosh
ID: 18825498
we must've put messages at the same time, I have my stored proc above. I also do not know if I'm setting my lengths correctly.
0
 
LVL 11

Accepted Solution

by:
dready earned 1000 total points
ID: 18825573
I think you set the size wrong, if im not mistaken, the third param is the lengh, so try this: (I chanced the 3rd param from 1 to 100 in 3 places.)

     myConnection.Open()

            Dim myCommand As New SqlCommand("usp_sel_getuser", myConnection)
            myCommand.CommandType = CommandType.StoredProcedure
            Dim uwuser As New SqlParameter("@user", SqlDbType.VarChar, 100)
            uwuser.Value = txtEmail.Text
            myCommand.Parameters.Add(uwuser)
            Dim pass As New SqlParameter("@password", SqlDbType.VarChar, 100)
            pass.Value = txtPassword.Text
            myCommand.Parameters.Add(pass)
            Dim success As New SqlParameter("@success", SqlDbType.Int, 4)
            success.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(success)
            Dim userid As New SqlParameter("@userid", SqlDbType.VarChar, 100)
            userid.Direction = ParameterDirection.Output
            myCommand.Parameters.Add(userid)
            myCommand.ExecuteNonQuery()

            Dim count As Int16 = success.Value
            Session("userid") = userid.Value

            lblcount.Text = count

            myConnection.Close()
0
 

Author Comment

by:jrmcintosh
ID: 18825780
That was it, thanks.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question