Rivx Posted April 13, 2012 Report Share Posted April 13, 2012 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 More sharing options...
AshWilliams Posted April 14, 2012 Report Share Posted April 14, 2012 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 More sharing options...
Rivx Posted April 14, 2012 Author Report Share Posted April 14, 2012 (edited) Revisando. Gracias por el tiempo.聽:8)聽PD: Edito, puse lo de la gu铆a, sin embargo, ahora no crea nada.聽:8) Edited April 14, 2012 by Rivx Link to comment Share on other sites More sharing options...
AshWilliams Posted April 14, 2012 Report Share Posted April 14, 2012 De nada cumpa...para eso estamos ;) Link to comment Share on other sites More sharing options...
Rivx Posted April 14, 2012 Author Report Share Posted April 14, 2012 PD: Edito, puse lo de la gu铆a, sin embargo, ahora no crea nada. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now