IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP Discussion :

récupération de variable de procédure stockée dans code asp


Sujet :

ASP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 21
    Points : 20
    Points
    20
    Par défaut récupération de variable de procédure stockée dans code asp
    Bonjour,
    Je programme en asp et le sgbd est sql server.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    CREATE PROCEDURE home
    	@utilisateur char(20), @criteredetri char(50)
    AS BEGIN
     
    	declare @msgclaire char(50)
    	declare @msgsa char(50)
    	declare @errno integer
    	IF @utilisateur='claire'
    		begin
    			if @criteredetri='responsable'
    			SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  responsable
    			if @criteredetri='société'
    			SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  société
    			if @criteredetri='nom'
    			SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  nom
    			if @criteredetri='prénom'
    			SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  prénom
     
    /*RETURN*/
     
    set @msgclaire= 'opération bien déroulée pour CLAIRE'
    set @errno = 30002   
    RAISERROR @errno @msgclaire
     
     
    /*set @msgclaire = 'opération bien déroulée pour CLAIRE'*/
    /*RAISERROR 60000 @msgclaire*/
     
    end	
     
    ELSE ........suite de la procédure................

    Mon problème :
    J'ai besoin de récupérer la valeur de ma variable "set @msgclaire" dans mon code asp.
    D'autant plus que cette procédure ne conient pas de rollback, alors que j'aurai besoin d'en coder qui en contiennent.
    Dans ce cas, si il y a rollback, mon code asp doit pouvoir récupérer au moins la valeur du raiserror de la procédure.

    Pour résumer, il y a deux problemes :
    Je veux récupérer dans mon code asp - 1 : une valeur de variable , - 2 : un message d'un "raiserror" et pour completer, un message de "print".

    J'ai fait beaucoup de recherches infructueuses sur ce sujet (mais j'ai peut etre mal cherché...).
    Merci

  2. #2
    Membre expérimenté Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 47
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Points : 1 352
    Points
    1 352
    Par défaut
    Il faut deja que tu declares tes variables en output pour les recuperer et et ensuite :
    retour=objcommand.parameters("@msgclaire ")
    voili voilou j'espere que cela t'aura filé des pistes

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 21
    Points : 20
    Points
    20
    Par défaut
    Bonjour Arthis,

    Merci énormément pour ta réponse.Elle m'a permis de découvrir un exemple à cette page : http://www.aspfree.com/c/a/Database/...-return-value/

    Voici le code que j'ai mis dans ma page à partir de celui du lien :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    dim parametreoutput
    parametreoutput="goooooo"
    dim parametre
    dim criteredetri
     
    dim conn
    dim rs
    dim i
    parametre=session("login")
    if request.querystring("criteredetri")=""then
    criteredetri="responsable"
    else
    criteredetri=request.querystring("criteredetri")
    endif
     
    '-------------------------------------------------------------
    Dim CmdSP 'conn
    Dim adoRS 'rs
    Dim adCmdSPStoredProc
    'Dim adParamReturnValue
    'Dim adParaminput
    'Dim adParamOutput
    'Dim adInteger
    'Dim iVal
    'Dim oVal
    'Dim adoField
    'Dim adVarChar
     
    'adCmdSPStoredProc = 1
    'adParamReturnValue = 4
    'adParaminput = 1
    'adParamOutput = 2
    'adInteger = 3
    'adVarChar = 200
     
    '-- Create a command object --
    Set conn=Server.createObject("ADODB.Command")
    '-- Make an ODBC connection to the (local)
    conn.ActiveConnection= "Driver={SQL Server};server=(local);Uid=sa;Pwd=saturne;Database=essai"
     
    '-- define the name of the command 
    conn.CommandText= "home" 
    '-- define the type of the command as a stored procedure (numeric value = 4)
    conn.CommandType= adCmdSPStoredProc
     
    '-- define the first parameter - the one the procedure will return
    '-- the calls are:
    '-- CmdSP.Parameters.Append: append this parameter to the collection for this command object
    '-- CmdSP.CreateParameter(): creates the parameter using the values given:
    '-- "RETURN_VALUE" is the name of the parameter for later reference
    '-- adInteger (value = 3) indicates this parameter is an integer datatype
    '-- adParamReturnValue (value = 4) indicates this parameter is expected to be returned
    '-- 4 is an arbitrary initial value for this parameter
     
    'conn.Parameters.Append conn.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 4)
     
     
    '-- define the first parameter - the one the procedure will return
    '-- the calls are:
    '-- CmdSP.Parameters.Append: append this parameter to the collection for this command object
    '-- CmdSP.CreateParameter(): creates the parameter using the values given:
    '-- "@au_lname" is the name of the parameter for later reference
    '-- adVarChar (value = 200) indicates this parameter is a string datatype
    '-- adParamInput (value = 1) indicates this parameter is for input
    '-- 20 is the size of the string in characters
    '-- "M" is an arbitrary initial value for this parameter
     
    conn.Parameters.Append conn.CreateParameter("@utilisateur", adVarChar, adParaminput, 20, parametre)
     
     
    '-- define the first parameter - the one the procedure will return
    '-- the calls are:
    '-- CmdSP.Parameters.Append: append this parameter to the collection for this command object
    '-- CmdSP.CreateParameter(): creates the parameter using the values given:
    '-- "@intID" is the name of the parameter for later reference
    '-- adInteger (value = 3) indicates this parameter is an integer datatype
    '-- adParamInput (value = 1) indicates this parameter is for input
    '-- the blank is a failure to declare the size of the variable
    '-- iVal is an arbitrary initial value for this parameter, placed with the variable
     
    conn.Parameters.Append conn.CreateParameter("@criteredetri", adVarChar, adParamInput,50, criteredetri)
     
     
    '-- define the first parameter - the one the procedure will return
    '-- the calls are:
    '-- CmdSP.Parameters.Append: append this parameter to the collection for this command object
    '-- CmdSP.CreateParameter(): creates the parameter using the values given:
    '-- "@intIDOut" is the name of the parameter for later reference
    '-- adInteger (value = 3) indicates this parameter is an integer datatype
    '-- adParamOutput (value = 2) indicates this parameter is expected to return an output
    '-- oVal is an arbitrary initial value for this parameter, placed with the variable oVal
     
    conn.Parameters.Append conn.CreateParameter("@msg", adVarChar, adParamOutput,100, parametreoutput)
     
     
    '-- execute the command
    Set rs = conn.Execute
     
     
    '-- report parameter values, accessing each by name
    Response.Write "<p>@msg = " & conn.Parameters("@msg").Value& "</p>"
    'Response.Write "<p>Return value = " & conn.Parameters("RETURN_VALUE").Value & "</p>"
     
     
    '-- tidy up the handles
    'Set adoRS = nothing
    'Set CmdSP.ActiveConnection = nothing
    'Set CmdSP = nothing
    
    ............ puis traitement du recordset

    ...et voici le code de ma procédure, revu et corrigé...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
    CREATE PROCEDURE home
     @utilisateur char(20), @criteredetri char(50), @msg char(100) OUTPUT
    AS BEGIN
     
     IF @utilisateur='claire'
      begin
       if @criteredetri='responsable'
       SELECT responsable, société, nom, prénom, adressedemessagerie,
    téléphonebureau, paysbureau, initiales  FROM contacts order by  responsable
       if @criteredetri='société'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  société
       if @criteredetri='nom'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  nom
       if @criteredetri='prénom'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  prénom
       set @msg = 'ca a marché pour claire'   
       RETURN @msg
      end 
     
     ELSE
      begin
       if @criteredetri='responsable'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  responsable
       if @criteredetri='société'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau  FROM contacts order by  société
       if @criteredetri='nom'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  nom
       if @criteredetri='prénom'
       SELECT responsable, société, nom, prénom, adressedemessagerie, téléphonebureau, paysbureau, initiales  FROM contacts order by  prénom
     
       set @msg='opération bien déroulée pour SA'
        RETURN @msg
    end
    END
    GO

    Voila, j'ai donc adapté le code à mon cas.
    Mon navigateur indique l'erreur suivante :
    " Type d'erreur :
    ADODB.Connection (0x800A0E78)
    Operation is not allowed when the object is closed.
    /siteask/allcontactsEssaiParametreRetour.asp, line 65
    "
    C'est cette ligne qui est incriminée :
    conn.ActiveConnection "essaiask","sa","monmotdepasse"
    Je l'ai remplacée par :
    conn.ActiveConnection = "Driver={SQL Server};server=(local);Uid=sa;Pwd=monmotdepasse;Database=essai"

    et là j'ai :
    "
    Type d'erreur :
    ADODB.Command (0x800A0BB9)
    Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
    /siteask/allcontactsEssaiParametreRetour.asp, line 70
    "
    voila...je suis paumé...
    merci

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 21
    Points : 20
    Points
    20
    Par défaut
    tu vas me maudire...j'ai modifié mon code, la procédure s'exécute à merveille mais je n'arrive pas à récupérer mes variables de retour...
    ...et j'ose pas fournir mon code...

Discussions similaires

  1. Réponses: 3
    Dernier message: 15/04/2011, 10h46
  2. Réponses: 3
    Dernier message: 08/02/2010, 19h12
  3. Récupération résultat Procédure Stockée dans Vba Access
    Par lito74 dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 05/02/2010, 18h45
  4. Suppression de paramètre pour procédure stockée dans le code
    Par 24 faubourg dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 04/01/2006, 10h51
  5. Procédures stockées dans accèss?
    Par joe.lindien dans le forum MS SQL Server
    Réponses: 5
    Dernier message: 21/11/2003, 15h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo