an exception with this code
-
hi guys when i run this code it throw an exception but it run well inside SQL Server 2008
ALTER proc [dbo].[back_up_database]
as
ALTER DATABASE [vvvvvvvvvvv]
SET OFFLINE
go
BACKUP DATABASE [vvvvvvvvvvv]
TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
with NO_COMPRESSION
go
ALTER DATABASE [vvvvvvvvvvv]
SET ONLINE
goso what is the problem thanks, Mohamed El-Wehishy
-
hi guys when i run this code it throw an exception but it run well inside SQL Server 2008
ALTER proc [dbo].[back_up_database]
as
ALTER DATABASE [vvvvvvvvvvv]
SET OFFLINE
go
BACKUP DATABASE [vvvvvvvvvvv]
TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
with NO_COMPRESSION
go
ALTER DATABASE [vvvvvvvvvvv]
SET ONLINE
goso what is the problem thanks, Mohamed El-Wehishy
Mohamed El-Wehishy wrote:
when i run this code
What do you mean? Run it where/how?
Mohamed El-Wehishy wrote:
it throw an exception
What exception?
only two letters away from being an asset
-
hi guys when i run this code it throw an exception but it run well inside SQL Server 2008
ALTER proc [dbo].[back_up_database]
as
ALTER DATABASE [vvvvvvvvvvv]
SET OFFLINE
go
BACKUP DATABASE [vvvvvvvvvvv]
TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
with NO_COMPRESSION
go
ALTER DATABASE [vvvvvvvvvvv]
SET ONLINE
goso what is the problem thanks, Mohamed El-Wehishy
Don't you think maybe this belongs in the Database section as opposed to the C# section?
Check out the CodeProject forum Guidelines[^] The original soapbox 1.0 is back![^]
-
hi guys when i run this code it throw an exception but it run well inside SQL Server 2008
ALTER proc [dbo].[back_up_database]
as
ALTER DATABASE [vvvvvvvvvvv]
SET OFFLINE
go
BACKUP DATABASE [vvvvvvvvvvv]
TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
with NO_COMPRESSION
go
ALTER DATABASE [vvvvvvvvvvv]
SET ONLINE
goso what is the problem thanks, Mohamed El-Wehishy
You should post it to the General Database forum..:)
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
Mohamed El-Wehishy wrote:
when i run this code
What do you mean? Run it where/how?
Mohamed El-Wehishy wrote:
it throw an exception
What exception?
only two letters away from being an asset
ok man this is my code
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection cn = new SqlConnection("initial catalog=vvvvvvvvvvv;server=.;integrated security=sspi");
SqlCommand cmd = new SqlCommand("back_up_database", cn);
cmd.CommandType = CommandType.StoredProcedure;cn.Open(); int i = cmd.ExecuteNonQuery(); cn.Close(); if (i > 0) { MessageBox.Show("Your database is backed up"); } } catch(Exception ex) { MessageBox.Show("Sorry we can not back up your database"); } }
when i run this code it throw exception but when i execute the stored procedure
ALTER proc [dbo].[back_up_database]
as
ALTER DATABASE [vvvvvvvvvvv]
SET OFFLINE
go
BACKUP DATABASE [vvvvvvvvvvv]
TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
with NO_COMPRESSION
go
ALTER DATABASE [vvvvvvvvvvv]
SET ONLINE
goit completed successfully so what is wrong thanks for your interest Mohamed El-Wehishy
-
ok man this is my code
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection cn = new SqlConnection("initial catalog=vvvvvvvvvvv;server=.;integrated security=sspi");
SqlCommand cmd = new SqlCommand("back_up_database", cn);
cmd.CommandType = CommandType.StoredProcedure;cn.Open(); int i = cmd.ExecuteNonQuery(); cn.Close(); if (i > 0) { MessageBox.Show("Your database is backed up"); } } catch(Exception ex) { MessageBox.Show("Sorry we can not back up your database"); } }
when i run this code it throw exception but when i execute the stored procedure
ALTER proc [dbo].[back_up_database]
as
ALTER DATABASE [vvvvvvvvvvv]
SET OFFLINE
go
BACKUP DATABASE [vvvvvvvvvvv]
TO DISK = 'D:\SQLServerBackups\vvvvvvvvvvv.Bak'
with NO_COMPRESSION
go
ALTER DATABASE [vvvvvvvvvvv]
SET ONLINE
goit completed successfully so what is wrong thanks for your interest Mohamed El-Wehishy
Read the previous response. What is the exception that is being thrown????
only two letters away from being an asset
-
Read the previous response. What is the exception that is being thrown????
only two letters away from being an asset
why, WrongForumException, the most popular of all; what else could it be? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
-
why, WrongForumException, the most popular of all; what else could it be? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
hi guys please redirect me to a link or tutorial which help me i can not understand the reason thanks Mohamed El-Wehishy
-
hi guys please redirect me to a link or tutorial which help me i can not understand the reason thanks Mohamed El-Wehishy
You can't understand the reason for what? You still haven't given any useful information
only two letters away from being an asset
-
why, WrongForumException, the most popular of all; what else could it be? :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
I wouldn't say that. The original post should have made in clearer, but it does appear to be C# related question. If he/she could only understand what an exception is, we'll all know more.
only two letters away from being an asset
-
I wouldn't say that. The original post should have made in clearer, but it does appear to be C# related question. If he/she could only understand what an exception is, we'll all know more.
only two letters away from being an asset
You're right. While the OP started with SQL in the C# forum, it now figures in the DB forum showing C# code; and we may be about to find out what the exception is. :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!