I want to author some .NET code (preferably C#) that determines the number of expected parameters in an arbitrary SQL statement. For example, this statement
EXEC etlp.LogPackageEnd ?,?,?
expects 3 parameters.
As a SQL novice, I spent time reading other posts on how to solve this problem. I've already tried using the TSql100Parser.GetTokenStream, as suggested here, but it returned parse errors for each question mark. I also tried using Microsoft.SqlServer.Management.SqlParser.Parser.Parser.Parse() but got an error of Incorrect syntax near ?
I realize I could use a regex but I'm looking for a generic solution; my understanding is that the parameter format can change so question marks aren't the indicators.