EXECUTE SQL stored procedure

Hoping someone can help me with this. I am probably making it harder than it needs to be....

I want to place a button on an ASP page to launch a SQL stored procedure. I successfully put the button on my page as follows....

var strCallSyncButton = CRM.Button("Update Market for Resident","preparedatabase.gif", CRM.Url("CHS/LeadspCHSupdateMarket4Leads.asp"));

leadloglist.AddButton(strCallSyncButton);

The above will launch another ASP that has the stored procedure code. This is where I am sure I am missing something. Here is what I have....

My ASP page...

<!-- #include file ="sagecrm.js"-->

<!-- #include file ="spCHSupdateMarket4Leads.js"-->

My Code page...

// JScript source code

'Set the connection

'...............

'Set the command

DIM cmd

SET cmd = Server.CreateObject("ADODB.Command")

SET cmd.ActiveConnection = Conn

'Prepare the stored procedure

cmd.CommandText = "spCHSupdateMarket4Leads"

'Execute the stored procedure

cmd.Execute

Conn.Close

SET Conn = Nothing

Can anyone help me with what I am doing wrong? Or point me to an example of how to do this?

Any assistance would be greatly appreciated...Thanks!

  • 0

    Hi,

    What I understand from your above post is that you want to execute stored procedure on click of an button in asp page. As such there is no need to create an connection object simply use below snippet and your job will be done.

    //'execute procedure

    var SPRFMPRef = " exec <stored procedure name>";

    RecSPRFMPRef = eWare.CreateQueryObj(SPRFMPRef);

    RecSPRFMPRef.SelectSQL();

    Hope this helps!

    Regards,

    Dinesh

  • 0

    Thank you for the reply. I tried the above. However, I am thinking I am not understanding where you are telling me to place this snippet. Am I still using the asp page with javascript. Or does this snippet go with my button code? This is what I have now...

    My ASP page...

    My Code page...

    // JScript source code

    //'execute procedure

    var SPRFMPRef = " exec ";

    RecSPRFMPRef = eWare.CreateQueryObj(SPRFMPRef);

    RecSPRFMPRef.SelectSQL();

    When I try the above, Visual Studio tries to launch a debugger...but does not really do anything.

    Any assistance is greatly appreciated...Thanks!

  • 0

    Hi,

    It will work just replace with spCHSupdateMarket4Leads. Check out below snippet.


    //'execute procedure
    var SPRFMPRef = " exec spCHSupdateMarket4Leads";
    RecSPRFMPRef = eWare.CreateQueryObj(SPRFMPRef);
    RecSPRFMPRef.SelectSQL();


    Regards,
    Dinesh

  • 0

    Hi...

    Again, thank you for the reply.

    I still cannot get this to work. Is there something that I need to set from within the Sage CRM interface to allow the stored procedure to run? If I run the stored procedure in management studio, it runs fine.

    However, if I try to run it from the button, a debugger tries to open in Visual Studio on the DB server. It really does not tell me much other than....An unhandled exception occurred in w3wp.exe [5332].

    Any thoughts on what I am doing wrong? Any assistance is greatly appreciated!

  • 0

    Michele

    Try (only) the following in your asp file:

    <%

    CRM.ExecSql("exec spCHSupdateMarket4Leads");

    %>

    paul

  • 0

    Paul:

    Thank you for the response. However, the SP will still not run from within Sage CRM. I went to the asp page and entered only....

    <%

    CRM.ExecSql("exec spCHSupdateMarket4Leads");

    %>

    I got the same result...a debugger tries to open in Visual Studio on the DB server. It really does not tell me much other than....An unhandled exception occurred in w3wp.exe [5332].

    I think you are supposed to execute the stored procedure from an asp page..so I cannot figure out what I am doing wrong!!

    Any other ideas?

  • 0

    Does anything appear in the event logs regarding the exception?

  • 0

    do you have rights for running stored procedures in the sql db for the db user you are using