0

I can't seem to find anything related to this problem. So I have a web-app I'm building using AngularJS and the others (html,etc) for UI, which connects with an Entity Framework in Asp.net (Either API or MVC, I'm not sure) for rest calls. That then connects to a sql database for model retrieval.

I have a SQLCMD which executes a stored procedure and creates a new time-stamped file of records from the database. The idea is that users will be able to click a button in the interface and a file will be generated without anyone ever having to touch sqlserver that they cna then put into excel. This has lead me on a search of topics like "WebMethods to call sqlcmd", "Calling .net webmethods with Angularjs", and "executing stored procedures with ASP.net", but nothing seems to be similar to what I'm asking (which leads me to believe maybe I don't have the best idea and it can be done better).

Any ideas? Just some pointers on where I should start or how I can tackle the problem would be greatly appreciated. I don't even have to return anything, it just needs to execute so this file can be created.

byteGeist
  • 73
  • 1
  • 6

2 Answers2

0

Your problem has nothing to do with AngularJS. AngularJS is just some client side code that will eventually call MVC or WebApi code (as you state).

Your problem is .. having server side dotnet code call an external .exe.

http://dotnetslackers.com/community/blogs/haissam/archive/2007/02/02/Run-Executable-file-in-ASP.NET.aspx

// Create An instance of the Process class responsible for starting the newly process.

System.Diagnostics.Process process1 = new System.Diagnostics.Process();

// Set the directory where the file resides

process1.StartInfo.WorkingDirectory = Request.MapPath("~/");

// Set the filename name of the file you want to open

process1.StartInfo.FileName = Request.MapPath("WindowsMediaPlayer.exe"); 
// Start the process
process1.Start();

You just need to get familiar with System.Diagnostics.Process.

One big gotcha will be permissions (that is running the IIS) being able to run sqlcmd.exe.

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
  • I think I am using MVC, since this app (I inherited the work for it) has folders for controllers, models, services and views. Where should I place this instance of the Process class so Angular can eventually call it? Currently if I try the first line in any controller or other class it does not even see the "process1" class after instantiation. I am very new to .net, thanks for your input. – byteGeist Apr 05 '16 at 21:17
  • Create a BusinessLogic layer assembly and have MVC reference it. you'll do this by "Add new CSProject" (C# Library)....and make a project reference from MVC to the BusinessLogic assembly/csproj. See https://msdn.microsoft.com/en-us/library/ee658109.aspx – granadaCoder Apr 05 '16 at 21:20
  • Oops, its definitely API, since its the prefix when a new class is added. Idk if that makes a big difference, but I don't see options for adding a new project (unless you mean create a new project, in which case I'd rather not do that) – byteGeist Apr 05 '16 at 21:32
0

I ended up doing a completely different idea and exported directly from Angular, Export to xls using angularjs, and did'nt worry about .NET or SQL for it.

This was way simpler and is better for me since the user can actually select what they want to export rather than just a total database dump.

Community
  • 1
  • 1
byteGeist
  • 73
  • 1
  • 6