Jump to content

[Resolvido] Backup BD


gastao

Recommended Posts

boa noite,

tou a fazer um programa de backups em que tou a usar sqlexpress 2014 no caso em questão mas penso ser igual e aplicavel em todos.

ao fazer a rotina de backup ele nao me faz o backup da base de dados, estou a fazer algo errado?

'assim nao funciona		  
  'Dim consql As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection("Data Source='" & serversql & "'; Integrated Security=false; User Id=sa;Password=rd;")

'assim funciona
Dim consql As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection("Data Source=127.0.0.1\sqlexpress; Integrated Security=false; User Id=sa;Password=rd;")

			Dim cmd As SqlCommand
			cmd = New SqlCommand("backup database nomebd to disk ='D:\teste\filename.bak'", consql)
			consql.Open()
			cmd.CommandTimeout = 800
			cmd.ExecuteNonQuery()
			consql.Close()
Edited by gastao
Link to comment
Share on other sites

Boas,

Fiz agora um teste com o código que tenho abaixo e funcionou perfeitamente. Fiz inclusive um RESTORE e não tive nenhum problema.

Dá-te algum erro quando tentas fazer o backup?

Private Sub backup()
Dim connectionString as String = "Data Source=.\SQLEXPRESS;Database=bd;MultipleActiveResultSets=True;User Id=sa;Password=pw"
Using conexao As New SqlClient.SqlConnection(connectionString)
  Using cmd As New SqlClient.SqlCommand("backup database bd to disk='D:\bd.bak'", conexao)
	conexao.Open()
	cmd.ExecuteNonQuery()
  End Using
End Using
 End Sub

Cumps

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.