How to Suppress the SELECT Output of a Stored Procedure called from another Stored Procedure in SQL Server?

后端 未结 10 2057
误落风尘
误落风尘 2020-12-15 14:50

I\'m not talking about doing a \"SET NOCOUNT OFF\". But I have a stored procedure which I use to insert some data into some tables. This procedure creates a xml response s

10条回答
  •  不思量自难忘°
    2020-12-15 15:41

    From which client are you calling the stored procedure? Say it was from C#, and you're calling it like:

    var com = myConnection.CreateCommand();
    com.CommandText = "exec insertSomeData 1";
    var read = com.ExecuteReader();
    

    This will not yet retrieve the result from the server; you have to call Read() for that:

    read.Read();
    var myBigString = read[0].ToString();
    

    So if you don't call Read, the XML won't leave the Sql Server. You can even call the procedure with ExecuteNonQuery:

    var com = myConnection.CreateCommand();
    com.CommandText = "exec insertSomeData 1";
    com.ExecuteNonQuery();
    

    Here the client won't even ask for the result of the select.

提交回复
热议问题