0

I want to write or insert stored procedure into a SQL Server database from a console application in C#. How can I do this?

I have a stored procedure in a SQL script file and it's in one folder in my console application folder. Now how can I insert or write that stored procedure in SQL Server when my console app is running?

Regards

3
  • Open the script file, read it, open the database connection, create a command with the script data, execute the command. And hope that none has tampered with your script Commented Mar 3, 2014 at 10:25
  • You should really rewrite your question. It is very unclear what you are trying to achieve. Commented Mar 3, 2014 at 10:25
  • Have a look in the below link, stackoverflow.com/questions/650098/… Commented Mar 3, 2014 at 10:26

2 Answers 2

2

Take a look Here and Here. Those links might help you to get through it.

Sign up to request clarification or add additional context in comments.

Comments

1

You execute an action statement against a database by calling ExecuteNonQuery on a SqlCommand. If you want to actually execute the script file rather than just the SQL code it contains then you can use Process.Start to run SQLCMD. I'm not sure of the exact commandline but you can look that up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.