Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Parameters to Executable

    Summary:
    I'm trying to pass variables from an ASP query to an executable.

    There are two files:
    events.asp - this queries the database and displays the ParentEventID and the KPName.

    Code:
    <%
    Option Explicit
    Dim rsqdb, rsqdba, parenteventid
    Dim strConnection, conn, neventID
    set Conn=Server.CreateObject("ADODB.Connection")
    set rsqdb = server.CreateObject("ADODB.Recordset")
    Conn.open "Provider=sqloledb;Server=myserver;Initial Catalog=qdb;UID=Reports;PWD=pw;"
    set rsqdb = conn.Execute ("SELECT ParentEventID, KPName FROM Object " )
    
    if rsqdb.EOF then
     Response.Write "There are no events"
     Response.End
    end if
    %>
    
    <html>
    
    <table>
      <td><font face="Verdana" size=1>
       <input id="kpname" name="kpname" value="<%response.write rsqdb("kpname")%>">
      </td>
      <td><font face="Verdana" size=1>
            <a href="test5.asp?parenteventid=<%response.write rsqdb("parenteventid")%>">
            <%response.write rsqdb("ParentEventID")%></a>
      </td>
     </tr>
      <%rsqdb.MoveNext%>
      <%loop%>
    
    </table>
    </html>
    
    <%do while not rsqdb.EOF%></do>
    <%response.write rsqdb("name")%>
    <%response.write ("<br> ")%>
    <%rsqdb.MoveNext%>
    <%loop%>
    
    <%
    set rsqdb = nothing
    set conn = nothing
    %>
    submit.asp - This file attempts to pass the kpname form the query and open a Remedy ticket. Note: When I run submit.asp as a standalone file (with dummy information), it generates a Remedy ticket.

    Code:
    <%
    Response.Buffer = false
    Dim kpname, parenteventid
    Function ChkString(string)
    If string = "" Then string = " "
    ChkString = Replace(string, "'", "'")
    End Function
    kpname = ChkString(Request.QueryString("kpname"))
    parenteventid = ChkString(Request.QueryString("parenteventid"))
    set Conn=Server.CreateObject("ADODB.Connection")
    Conn.open "Provider=sqloledb;Server=myserver;Initial Catalog=qdb;UID=Reports;PWD=pw;"
    
    mysql = "SELECT ParentEventID, AgentMsgShort, KPName from Object " _
    & " where parenteventid = '" & Request.QueryString("parenteventid") &"' ")
    
    Set RS = conn.execute (mysql)
    Set WShell = CreateObject("WScript.Shell")
    wshell.run "D:/InCharge8T2/SAM.Adapters/smarts/bin/sm_arclient.exe --server=""remedy-server"" --user=""dalesmarts"" --password=""dalesmarts"" createEntry ""InCharge SAM Schema""  2 c ""smarts"" 7 e 1  8 c  " & KPname & "  1042601003 c ""Server"" 1042601004 c ""exchange-server"" 1042601007 d ""Paging File Usage High; Paging File Usage% is 98.84; >TH = 95"" "
    Set WShell = nothing
    response.write "Submitted Remedy Ticket"
    if rs.EOF then
    Response.Write "There is no data"
    Response.End
    end if
    %>
    However, there are two problems I'm having:

    1. When I click the hyperlink in events.asp (which calls submit.asp), the executable doesn't run. Note: I've left some dummy data in the call along with my attempt to pass the KPName data from the query.

    2. I'm not sure that the KPName syntax is correct.

    Any help is appreciated.

    Dale

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    NO PLACE in the first code do you show us where and how you are calling "submit.asp".

    So how can we guess whether, indeed, you are calling it with the correct parameters in the query string?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    When I click the hyperlink in events.asp (which calls submit.asp),...
    No, the hyperlink calls "test5.asp".

    And that first set of code can't possibly be real. You have LOOP statement but there is no corresponding WHILE.

    Your HTML isn't close to legal. You have <font> tags with no matching </font>s. And <font> is obsolete, in any case.

    And what is the point of <input id="kpname" name="kpname" ... when there is no <form> to contain it and it is not used at all? Why use an <input> instead of just putting the text directly in the <td>??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    My apology. I was trying to sanitize my code and really jumbled it up. So here's what I'm trying to do.

    I want the hyperlink that calls/links to test5.asp to pull the parenteventid and kpname, and the pass that to the exeutable in test5.asp.

    Below is the test5.asp that I should have posted:

    Code:
    <%
    Response.Buffer = false
    Dim kpname, parenteventid
    Function ChkString(string)
    If string = "" Then string = " "
    ChkString = Replace(string, "'", "'")
    End Function
    
    kpname = ChkString(Request.QueryString("kpname"))
    parenteventid = ChkString(Request.QueryString("parenteventid"))
    
    set Conn=Server.CreateObject("ADODB.Connection")
    set rsqdb = server.CreateObject("ADODB.Recordset")
    
    Conn.open "Provider=sqloledb;Server=server;Initial Catalog=qdb;UID=;PWD=;"
    
    mysql = "SELECT ParentEventID, KPname " _
    & " FROM event " _
    & " where parenteventid = '" & Request.QueryString("parenteventid") &"' "
    Set RS = conn.execute (mysql)
    
    Set WShell = CreateObject("WScript.Shell")
    wshell.run "D:/InCharge8T2/SAM.Adapters/smarts/bin/sm_arclient.exe --server=""remedyserver"" --user=""smartsid"" --password=""smartsid"" createEntry ""InCharge SAM Schema""  2 c ""smarts"" 7 e 1  8 c  """ & KPname & """  1042601003 c ""Server"" 1042601004 c ""exchange-server"" 1042601007 d ""Paging File Usage High; Paging File Usage% is 98.84; >TH = 95"" "
    Set WShell = nothing

    However, I can't figure out the correct syntax for the kpname variable in the command line. I've tried multiple double-quotes/single-quotes with/without spaces. Eventually, everything will get pulled.

    Thanks again.

    Dale

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Okay, first of all, if you are going to pass both kpname from the first page to the second, then why do you need to make a database query, at all, in the second page?

    However, currently, your first page is *NOT* passing KPName, *AT ALL*, and so of course when you do
    Code:
     kpname = ChkString(Request.QueryString("kpname"))
    you are simply getting a blank string into kpname. So of course the call to the executable doesn't work.

    Now... You *COULD* get kpname from the SQL Query you do on the second page, but you aren't doing that in the code you show.

    So you need to make up your mind: (a) ARE you going to pass KPName in the query string? (b) If so, why do you need the SQL query in the second page, at all?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So here's the code that I used to test that I'm pulling kpname:

    Code:
    <%
    Response.Buffer = false
    Dim kpname, parenteventid
    Function ChkString(string)
    If string = "" Then string = " "
    ChkString = Replace(string, "'", "'")
    End Function
    
    kpname = ChkString(Request.QueryString("kpname"))
    parenteventid = ChkString(Request.QueryString("parenteventid"))
    set Conn=Server.CreateObject("ADODB.Connection")
    set rsqdb = server.CreateObject("ADODB.Recordset")
    Conn.open "Provider=sqloledb;Server=server;Initial Catalog=qdb;UID=;PWD=;"
    %>
    
    <html>
    <table border>
    <%
    mysql = "SELECT ParentEventID, KPname " _
    & " FROM event " _
    & " where parenteventid = '" & Request.QueryString("parenteventid") &"' "
    Set RS = conn.execute (mysql)
    Do Until RS.EOF
    %>
    
    <tr>
    <td><b>Name:</b> <%=RS("kpname")%><%=RS("parenteventid")%><br>
    </tr>
    
    <%
    RS.MoveNext
    Loop
    RS.Close
    %>
    </table>

    And it worked just fine. What else am I missing? I just replaced the HTML code with the call to the executable.

    Thanks!
    Dale

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    THIS is what you were not doing in the first two code postings:
    Code:
     <%=RS("kpname")%>
    Look at your own code (here on multiple lines for clarity):
    Code:
    wshell.run "D:/InCharge8T2/SAM.Adapters/smarts/bin/sm_arclient.exe " _
              & " --server=""remedyserver"" --user=""smartsid"" --password=""smartsid"" " _
              & " createEntry ""InCharge SAM Schema""  2 c ""smarts"" 7 e 1  8 c  """ _
              & KPname & """  1042601003 c ""Server"" 1042601004 c ""exchange-server"" " _
              & " 1042601007 d ""Paging File Usage High; Paging File Usage% is 98.84; >TH = 95"" "
    See? You were using the BARE VARIABLE NAME kpname.

    And that variable came from THIS LINE in your code:
    Code:
    kpname = ChkString(Request.QueryString("kpname"))
    And, as I previously pointed out, since you are *NOT* passing that in the ACTUAL querystring from the first page, it will of course be BLANK!

    ***********

    Again...MAKE UP YOUR MIND. You *CAN* pass kpname in the querystring from the first page, if you wish. Easy to change the code on the first page to do so.

    Or you can get it from the recordset.

    But it makes no sense to create the recordset and than just ignore the value from the recordset.

    Personally, I would get rid of all the sql on that second page, if the ONLY purpose is to get kpname, and just pass kpname in the querystring.

    You do that in your FIRST PAGE by changing this code:
    Code:
            <a href="test5.asp?parenteventid=<%response.write rsqdb("parenteventid")%>">
            <%response.write rsqdb("ParentEventID")%></a>
    to this:
    Code:
    <%
            ' you *REALLY* need to URLEncode when you put stuff in a query string:
            eid = Server.URLEncode(rsqdb("parenteventid"))
            kpname = Server.URLEncode(rsqdb("kpname"))
    %>        
            <a href="test5.asp?parenteventid=<%=eid%>&kpname=<%=kpname%>">
                <%=rsqdb("ParentEventID")%>
            </a>
    Oh...and do learn to use <%=xxx%> in place of <%response.write xxx%>. It makes no difference to ASP but it makes your code tons easier to read and write.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Jun 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Old Pedant,

    As usual, (you've helped me before), you were right on the money. I'm a little dense sometimes and I miss the obvious. Thank you so much for your help.

    Regards,
    Dale

    P.S. Do you still hang out at p2pwrox?

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,133
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Quote Originally Posted by dalezjc View Post
    P.S. Do you still hang out at p2pwrox?
    Haven't for a while. I should go back there.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •