BACKUP DATABASE timeout expired.

I get this error message when  I try to run my BACKUP DATABASE Strored Procedure as a command in VS 2005.

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

' Code
Dim strTempCnn As String = "user id=myUser;password=MyPassword;data source=MyServer;" & _
        "persist security info=True;initial catalog=MyDatabase;Connect Timeout=0"

        Dim TempCnn As SqlClient.SqlConnection = New SqlClient.SqlConnection(strTempCnn)

        Try

            Dim cmdBU As SqlClient.SqlCommand = New SqlClient.SqlCommand

            cmdBU.Connection = TempCnn
            cmdBU.CommandType = CommandType.StoredProcedure
            cmdBU.CommandText = "[dbo].[BackUpDataBase]"

            If TempCnn.State <> ConnectionState.Open Then
                TempCnn.Open()
            End If

            cmdBU.ExecuteNonQuery()

        Catch ex As Exception

            MsgBox(ex.ToString)

        End Try

        TempCnn.Close()

    End Sub

My Stored Procedure is:

BACKUP DATABASE MyDatabase
TO DISK = N'c:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\MyDatabase.Bak'
   WITH FORMAT,
   NAME = N'MyDatabase-Full Database Backup'    

END

However when i execute the Stored Procedure in SQL Server it executes fine and completes in 55 seconds.

Also in my connection string, I have changed the connect timeout property to various amounts and still get same error message.

Any ideas?
LVL 1
EamonAsked:
Who is Participating?
 
DhaestCommented:
Try to add a timeout on your command-object

cmdBU.CommandTimeout = 120
0
 
EamonAuthor Commented:
Thanks Dhaest..

Seems to run fine now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.