Jump to content

Problemas con respaldo y restauraci贸n SQL Server 2008


Recommended Posts

Hola a todos gente de (驴)bien(?)

Les cuento: debo hacer un respaldo en .bak de una base de datos, y en teor铆a la hace. Pero por ejemplo, al probar ese archivo en SQL Management Studio, me sale el bak esta mal hecho. Adjunto el c贸digo para aquella alma caritativa que se apiade de este humilde programador.

Va mi intento de backup y restore. Para conocimiento, la ruta de donde quedar谩 guardado la saca de un FileDialog:

Dim destino As String
	Dim dlgDestino As New FolderBrowserDialog
	With dlgDestino
		.Description = "Seleccione el directorio de destino:"
		If .ShowDialog = Windows.Forms.DialogResult.OK Then
			Dim strDestino As String = .SelectedPath.ToString
			If Not strDestino.EndsWith("\") Then
				strDestino = strDestino & "\"
			End If
			destino = strDestino & ""
		End If
	End With
	Dim cadena_conexion As String = "data source=NOMBRESERVER;" & "Initial Catalog=rlm;" & "Integrated Security=true"
	Dim variconex As New SqlConnection()

	variconex = New SqlConnection(cadena_conexion)
	variconex.Open()
	If variconex.State = ConnectionState.Open Then
		Try
			Dim fhActual As DateTime = Date.Now()
			Dim ruta As String
			Dim fActual As String = fhActual.Year.ToString().Trim() & _
									fhActual.Month.ToString().Trim().PadLeft(2, "0") & _
									fhActual.Day.ToString().Trim().PadLeft(2, "0")
			Dim hActual As String = fhActual.Hour.ToString().Trim().PadLeft(2, "0") & _
									fhActual.Minute.ToString().Trim().PadLeft(2, "0") & _
									fhActual.Second.ToString().Trim().PadLeft(2, "0")
			Dim servic As String = "NOMBRESERVER"
			Dim bas As String = "rlm"
			ruta = fActual & hActual & servic & bas
			Dim sCmd As New StringBuilder
			sCmd.Append("BACKUP DATABASE [" + bas + "] TO  DISK = N'" + dlgDestino.ToString + "' ")
			sCmd.Append("WITH DESCRIPTION = N'" + ruta + "', NOFORMAT, NOINIT, ")
			sCmd.Append("NAME = N'" + ruta + "', SKIP, NOREWIND, NOUNLOAD,  STATS = 10")
			Dim cmd As New SqlCommand(sCmd.ToString, variconex)
			cmd.ExecuteNonQuery()
			MessageBoxEx.Show("Respaldo creado con 茅xito", "Felicidades", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information)
		Catch ex As Exception
			MessageBoxEx.Show("No se pudo realizar el Respado", "ERROR", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
		Finally
			variconex.Close()
		End Try
	End If
End Sub

Espero puedan ayudarme. Nos vemos.

:8)

Link to comment
Share on other sites

Tal vez tenga algo que ver con los permisos y por eso el backup queda mal hecho...ojo que con esa forma no se sobreescriben los backups...yo que tu seguir铆a esta gu铆a, yo la encontr茅 muy buena:

http://es.scribd.com/doc/13482364/Respaldar-bases-de-datos-de-SQL-Server-con-Visual-Basic-NET

Saludos :krider:

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...