gastao Posted February 16, 2016 at 02:12 AM Report Share #593556 Posted February 16, 2016 at 02:12 AM (edited) 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 February 16, 2016 at 02:31 AM by gastao Link to comment Share on other sites More sharing options...
Soulsick Posted February 16, 2016 at 03:14 AM Report Share #593559 Posted February 16, 2016 at 03:14 AM 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 More sharing options...
gastao Posted February 16, 2016 at 10:38 AM Author Report Share #593570 Posted February 16, 2016 at 10:38 AM (edited) Nao me da erro algum... a unica coisa q tou a trocar é a conexao q tou a usar variáveis globais... e pelas variáveis como demonstro nao faz, e direto ele efetua o backup sem problema... Edited February 16, 2016 at 11:27 AM by gastao Link to comment Share on other sites More sharing options...
gastao Posted February 16, 2016 at 10:38 AM Author Report Share #593571 Posted February 16, 2016 at 10:38 AM (edited) resolvido, e funciona como estou a fazer... foi por ser tarde 😉 Edited February 16, 2016 at 12:51 PM by gastao Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now