none
how to create a stored procedure in SQL Server using C# (ADO.NET)

    Question

  • hi, group,

    Is that possible to create a stored procedure in SQL database using C# (ADO.NET)? I can compose a stored procedure at client side and click a button, this store procedure will be created in the SQL Server.

    thanks.
    Saturday, August 16, 2008 6:09 PM

Answers

  • We store our stored procedure scripts in a Database project. It gives you the ability to execute .sql files against the sql server from inside of Visual Studio.

    If you're talking about doing dynamic stored procedure generation, then you can do that using SQL commands (CREATE PROCEDURE). Be sure to drop the old one if you're changing it.


    KodefuGuru.com - Life Student of the Kodefu Arts
    • Marked as answer by Tao Liu Monday, August 18, 2008 5:54 PM
    Saturday, August 16, 2008 9:53 PM
  • Is that possible to create a stored procedure in SQL database using C#

    The answer is YES. 

    Take a look at Microsoft.SqlServer.Management.Smo object and the whole namespace as well as Linq To Sql concept. There is a way o generate Stored Procedures on the fly and drop them. Otherwise you can do what Chris said. I have been doing it for months but am planning to switch to Linq.

    Stored Procedures (LINQ to SQL)

    If you have anything better than SqlExpress you can use CLR SPs thru Integration Services.

    AlexB
    Monday, August 18, 2008 12:20 AM

All replies

  • We store our stored procedure scripts in a Database project. It gives you the ability to execute .sql files against the sql server from inside of Visual Studio.

    If you're talking about doing dynamic stored procedure generation, then you can do that using SQL commands (CREATE PROCEDURE). Be sure to drop the old one if you're changing it.


    KodefuGuru.com - Life Student of the Kodefu Arts
    • Marked as answer by Tao Liu Monday, August 18, 2008 5:54 PM
    Saturday, August 16, 2008 9:53 PM
  • Is that possible to create a stored procedure in SQL database using C#

    The answer is YES. 

    Take a look at Microsoft.SqlServer.Management.Smo object and the whole namespace as well as Linq To Sql concept. There is a way o generate Stored Procedures on the fly and drop them. Otherwise you can do what Chris said. I have been doing it for months but am planning to switch to Linq.

    Stored Procedures (LINQ to SQL)

    If you have anything better than SqlExpress you can use CLR SPs thru Integration Services.

    AlexB
    Monday, August 18, 2008 12:20 AM