Last active
December 22, 2015 20:49
-
-
Save dshookowsky/6529572 to your computer and use it in GitHub Desktop.
Calling dynamic stored procedure results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped, Method = "POST", UriTemplate = "ExecuteReportData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] | |
public string ExecuteReportData(int parameter1, string reportName) | |
{ | |
try | |
{ | |
List<dynamic> returnList = new List<dynamic>(); | |
if (isApprovedUser()) | |
{ | |
using (var db = new MyReportingEntities()) | |
{ | |
var dbCommand = db.Database.Connection.CreateCommand(); | |
dbCommand.Connection.Open(); | |
dbCommand.CommandText = "GenerateReportData"; | |
dbCommand.CommandType = System.Data.CommandType.StoredProcedure; | |
dbCommand.AddParameterWithValue("@ReportName", reportName); | |
DbDataReader reader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection); | |
while (reader.Read()) | |
{ | |
returnList.Add(SqlDataReaderToExpando(reader)); | |
} | |
} | |
} | |
return JsonConvert.SerializeObject(returnList); | |
} | |
catch (Exception ex) | |
{ | |
logger.ErrorException(String.Format("ExecuteReportData({0}, {1})", parameter1.ToString(), reportName), ex); | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment