SQL Server database backup from C#, using stored procedure [closed] - sql-server

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Please help me I am using SQL Server. I want to create a backup to my device after action EXECUTION text execution in mvc C#.

Suppose you have BackUp method in HomeController, then execute the follwoing store procedure.
_dbcontext.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, #"EXEC [dbo].[spBackUpDatabases]");
and spBackUpDatabases store procedure is like
USE [TestAppDbContext]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spBackUpDatabases]
AS
BEGIN
SET NOCOUNT ON;
-- backup database TestAppDbContext to disk='D:/TestAppDb/test.bak'
exec( 'backup database TestAppDbContext to disk = N''D:/TestAppDb/test.bak'' with format, init;' );
END
I think this help u.

Related

SQL Alter Sequence on remote server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
On SQL Server, I'm trying to alter sequence on a remote server using this:
ALTER SEQUENCE SeverName.DbName.sys.SeqName_sequence RESTART WITH 1000;
Unfortunately, this does not work. Does anyone know if this is possible and the correct syntax?
You can do this using dynamic SQL, and specify that database's sp_executesql procedure.
DECLARE #sql nvarchar(max) = '
ALTER SEQUENCE SomeSchemaName.SomeSequenceName RESTART WITH 1000;
';
EXEC SeverName.DbName.sys.sp_executesql #sql;

Error calling stored procedure that have been created in MS SQL Server Management Studio [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
Let's say I have this procedure :
USE [base1]
GO
SET ANSI_WARNINGS OFF
GO
IF OBJECT_ID ( 'dbo.MyProcedure ', 'P' ) IS NOT NULL DROP PROCEDURE dbo.MyProcedure ;
GO
CREATE PROCEDURE dbo.MyProcedure
#code NVARCHAR(1000),
#Month INT,
#YEAR INT
AS
SET NOCOUNT ON;
-- my code
GO
-- END PROCEDURE
I use the procedure by following steps :
To create it i execute the script of procedure
The procedure is create in this database base1 not in master
I launch this command EXECUTE dbo.MyProcedure N'Test',03,2016; => i get the succesfull result
I disconnect from the server and i reconnect
I execute this : CEXECUTE dbo.MyProcedure N'Test',03,2016; => i get this error
Could not find stored procedure 'dbo.MyProcedure'.
So in custom database base1>Programmability >stored procedures => i can see the procedure it exists
Typically, default database on connection is master. so when you disconnected and reconnected, you most likely are in master database. You can verify by executing SELECT DB_NAME(). Since you created your proc in a different database, execution will fail until you switch databases or fully qualify your proc call.

How to call one stored procedure from another in SQL Server [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How to call one stored procedure from another stored procedure and when I do that. Then it is not updating in Crystal Report field explorer.
This is my code:
SP1
ALTER PROCEDURE [dbo].[GetSpecialJournalInfoByJVID]
(#JvID numeric,#BusinessID numeric)
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM JV
WHERE jvID = #JvID AND BusinessID = #BusinessID
END
SP2
ALTER PROCEDURE [dbo].[USP_GetSpecificAccountLedger]
#JvID numeric(18,0),
-- Add the parameters for the stored procedure here
#ParamDate1 datetime,
#ParamDate2 datetime,
#ParamBusinessID numeric(18,0),
#ParamAccountID numeric(18,0),
#ParamCurrentCurrencyRate decimal(18,10) =1
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT *
FROM JV
WHERE jvID = #JvID
-- Insert statements for procedure here
SELECT
COA.ACCOUNTID, COA.ACCOUNTNAME, COA.GLCODE,
COA.DESCRIPTION AS ACCOUNTDESCRIPTION,
COA.ISBANKACCOUNT, COA.BANKACCOUNTNO,
COA.REFACCOUNT, FIXED,
ISNULL(OPBAL.OPENINGBALANCE, 0) OPENINGBALANCE,
ISNULL(CURBAL.DR_CUR_BAL, 0) DR_CUR_BAL,
ISNULL(CURBAL.CR_CUR_BAL, 0) CR_CUR_BAL,
J.TRNDATE, J.TRNDESCRIPTION, TRNTYPE,
I need help, I googled it a lot but didn't got any solution
thanks in advance...
You can call a stored procedure by using the EXEC command. However, it might be better to use SQL Server user-defined function.
Please see: https://technet.microsoft.com/en-us/library/aa175085(v=sql.80).aspx

Incorrect syntax near the word 'END' in SQL [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm making a stored procedure in SQL but I get the error Incorrect syntax near the word 'END' at line 1 position 1 but the line 1 in my code is:
CREATE PROCEDURE [dbo].[upd_facility_new] #Tcifno int
Try this format:
USE [dbName]
GO
/****** Object: StoredProcedure [dbo].[SP_name] Script Date: 08/14/2015 10:34:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[SP_name]
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM TableName
END

Code runs fine in SQL Server, but fails at the time of deploying [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Please tell me as soon as possible?
create table aboutus_table
(
id int primary key identity(1,1),
content char(7500),
)
select * from aboutus_table
create procedure admin_aboutus_save
(#aboutus_content char(7500))
as begin
insert into aboutus_table(content)
values(#aboutus_content)
end
create procedure admin_aboutus_detail
as begin
select * from aboutus_table
end
create procedure admin_aboutus_detail_delete
(#aboutus_id int)
as begin
delete aboutus_table where id=#aboutus_id
end
create procedure admin_aboutus_detail_edit
(#aboutus_id int)
as begin
select * from aboutus_table where id=#aboutus_id
end
create procedure admin_aboutus_edited_save
(#aboutus_id int,
#aboutus_content char(7500))
as begin
update aboutus_table
set content = #aboutus_content
where id = #aboutus_id
end
This is my code. It is running fine in SQL Server, but at the time of deploying a website, when it am running above code in SQL Server, it is show error.
An exception occurred while executing a Transact-SQL statement or batch.
'CREATE/ALTER PROCEDURE' must be the first statement in a query batch.
Incorrect syntax near the keyword 'procedure'.
Must declare the scalar variable "#aboutus_id".
Must declare the scalar variable "#aboutus_id".
Must declare the scalar variable "#aboutus_id".
As the error states, CREATE PROCEDURE must be the first statement in a query batch.
To force a piece of SQL to run in a new query batch, either execute that code separately, or place GO before it in SSMS.

Resources