﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Backups / SQL Server 7,2000  / Run SQL backup proc within C# program / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Fri, 24 May 2013 16:15:43 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Run SQL backup proc within C# program</title><link>http://www.sqlservercentral.com/Forums/Topic922418-24-1.aspx</link><description>Try something like this:[code="plain"]string conn_str1="Data Source=localhost;Initial Catalog=master;User Id=sa;Password=xxxx;";using (SqlConnection conn = new SqlConnection(conn_str1)){    SqlCommand cmd = new SqlCommand();    cmd.Connection = conn;    cmd.CommandType = CommandType.StoredProcedure;    cmd.CommandText= [proc_name_here];    conn.Open();    cmd.ExecuteNonQuery();} [/code]Edit:  You'll have to add the parameter in separately, but that shouldn't be too much trouble.</description><pubDate>Wed, 07 Jul 2010 21:22:58 GMT</pubDate><dc:creator>justinb138</dc:creator></item><item><title>RE: Run SQL backup proc within C# program</title><link>http://www.sqlservercentral.com/Forums/Topic922418-24-1.aspx</link><description>Check this article: [url=http://www.shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html]HOW TO: SQL &amp; C#[/url] for details on how to connect to SQL Server database from C#.NET database applications as well as Java database applications. It also describes how to pass embedded SQL queries, calling stored procedures, pass parameters etc.[url=http://www.shahriarnk.com/]Shahriar Nour Khondokar[/url] </description><pubDate>Tue, 01 Jun 2010 06:44:41 GMT</pubDate><dc:creator>shr_khr</dc:creator></item><item><title>RE: Run SQL backup proc within C# program</title><link>http://www.sqlservercentral.com/Forums/Topic922418-24-1.aspx</link><description>Dear Lowell,Thanks for your comments.Actually I use the "SqlCommand.ExecuteNonQuery Method" in my c# applications.  Here is the partial codings in program :-------------//program body....       string [] UpDateCmd = new string[1];              UpDateCmd[0] = "EXEC master.dbo._PRM_bk 'E:\temp\PRM1005' ";       Trans_Data(UpDateCmd);       if (gUFlag) {         msgLbl.Text = "** Backup Completed  **";       } else          msgLbl.Text = "**  Error : Backup Failed  **"+UpDateCmd[0];     }......// New Proc: Add,Change,Delete functions with Array  public void Trans_Data(string [] Scmd)  {   string conn_str1="Data Source=localhost;Initial Catalog=master;User Id=sa;Password=xxxx;";    SqlConnection conn = new SqlConnection(conn_str1);    conn.Open();//  Start transaction    SqlTransaction myTrans = conn.BeginTransaction();      //  Assign command in the current transaction    SqlCommand cmd = new SqlCommand();    cmd.Connection = conn;    cmd.Transaction = myTrans;      //  Execute command          try    {      foreach (string SQLcmd in Scmd)      {        cmd.CommandText=SQLcmd;        cmd.ExecuteNonQuery();      }        myTrans.Commit();      gUFlag=true;    } catch {      myTrans.Rollback();      gUFlag=false;    }    cmd.Connection.Close();    conn.Close();  }------------The program result is always failed.  But it is okay to run in SQL Query Analyzer.  I don't have any idea on this issue.Thanks again for your help.Regards,Edward</description><pubDate>Sat, 15 May 2010 08:30:07 GMT</pubDate><dc:creator>edward-837480</dc:creator></item><item><title>RE: Run SQL backup proc within C# program</title><link>http://www.sqlservercentral.com/Forums/Topic922418-24-1.aspx</link><description>edward are you familiar with the       [b]SqlCommand.ExecuteNonQuery [/b]Method, that is part of the  (System.Data.SqlClient) class?that is how you'd call a command that has no expected results...insert/update/delete,  or in your case, calling a procedure to run.</description><pubDate>Sat, 15 May 2010 05:13:55 GMT</pubDate><dc:creator>Lowell</dc:creator></item><item><title>Run SQL backup proc within C# program</title><link>http://www.sqlservercentral.com/Forums/Topic922418-24-1.aspx</link><description>Dear experts,I create a Backup Proc named  _PRM_bk in Stored Procedures of master database.   I can execute this procedure under "SQL Query Analyzer" but failed to run under a C# program even I set the login user "sa" within the program.Server :   Windows 2003  run  ASP.NET 2.0 , SQL Server 2000Please suggest me how to run under a .NET application... Thanks a lot !Here is the procedure coding :-------------------------------------- Sys Proc to create Month-End backup before Month-End process-- useful cmd  to drop backup device:    select * from master.dbo.sysdevices---- run Query Analyzer cmd:   EXEC master.dbo._PRM_bk 'E:\temp\SkyPRMyymm'--CREATE PROCEDURE [dbo].[_PRM_bk]    @Fn varchar(100)AS BEGIN SET NOCOUNT ON-- Create a logical backup device for the full SkyPRM backup before month-end.-- USE master EXEC master.dbo.sp_addumpdevice 'disk','SkyPRM_bk',@Fn-- Back up the full SkyPRM database. BACKUP DATABASE SkyPRM TO SkyPRM_bk WITH NAME = 'SkyPRM_VERIFY'RESTORE HEADERONLY      -- Get File number = 1 FROM SkyPRM_bk-- Verify backup file, okay message : The backup set is valid.RESTORE VERIFYONLY FROM  SkyPRM_bk-- Delete device after backup EXEC master.dbo.sp_dropdevice 'SkyPRM_bk'ENDGO--------------</description><pubDate>Fri, 14 May 2010 22:57:45 GMT</pubDate><dc:creator>edward-837480</dc:creator></item></channel></rss>