it is wrong with this
-
this code throw exception hi guys when i run the next code it throw an exception
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"); } }
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
-
this code throw exception hi guys when i run the next code it throw an exception
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"); } }
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
Have you looked at the exception?
-
Have you looked at the exception?
i can not understand you man please explain your words i want to know why this exception throwed thanks for help Mohamed El-Wehishy
-
i can not understand you man please explain your words i want to know why this exception throwed thanks for help Mohamed El-Wehishy
Mohamed El-Wehishy wrote:
this exception
what exception? :~
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!
-
Mohamed El-Wehishy wrote:
this exception
what exception? :~
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!
you can see the first message i wait your response thanks Mohamed El-Wehishy
-
you can see the first message i wait your response thanks Mohamed El-Wehishy
Your code contains:
catch(Exception ex)
{
MessageBox.Show("Sorry we can not back up your database");
}which is moronic, the
ex
variable contains a lot of information, which you should look at by showing it, say withConsole.WriteLine(ex.ToString());
and instead you ignore it and then ask the world what is wrong?????????????????????????????????????????????????????????????????? :|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!
-
Have you looked at the exception?
-
comment try and catch and see what message it gives as error or you can write ex.message also to see the exception message
Best Of Regards, SOFTDEV If you have knowledge, let others light their candles at it
Or he could just learn to debug the code by setting a breakpoint.
only two letters away from being an asset