Run a C# funtion outside of the application

I have a ASP.Net web application, with c# code behind. The underlying database is SQL Server 2012. I have a web page that I can open with a button on it. Clicking that button runs a c# function that move data from a flat file to the SQL Server database. It works great. The problem is that you have to open the website and go to that page to click the button to run the code. When originally written, this was something that would need to be done very infrequently. Now I need to do it daily. I want to schedule something to run at a certain time after normal business hours. How can I schedule to run a c# function I have written as part of a web application? Can you run c# code from SQL Server in a stored procedure? Is this something that needs scripting? If so, I have no scripting experience, so I'm not sure where to start. Any help is appreciated. I'm using Visual Studio 2012, SQL Server 2012 on Windows Server 2012 R2.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Najam UddinCommented:
How about take that function and related code move it in a console application and schedule that application?
käµfm³d 👽Commented:
How can I schedule to run a c# function I have written as part of a web application?
Why not wrap up the core logic in a 2nd project that is a console application. Then you can simply use Windows Task Scheduler to run the console app on whatever schedule you like. There's also libraries like Quart.NET which you could use, but I imagine the Task Scheduler would suffice for this task.

Can you run c# code from SQL Server in a stored procedure?
Yes, via CLR Integration. You may want to discuss this with your DBAs, though. They may have concerns on using it.

I believe you can also shell out system calls, but I believe this is a security risk. Whereas you could wrap your current code in some kind of a console application and call it from the database, I doubt the security risk would be worth the gain.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.