Glimmerman
New member
- Local time
- Today, 19:08
- Joined
- Oct 9, 2012
- Messages
- 9
Hi im trying to make pass through query that triggers a database restore on a SQL server based on a few parameters entered in a form.
As soon as i run the command button the output just put all lines as one line without line breaks, can anyone help me on whats going wrong here?
Here is my code:
As soon as i run the command button the output just put all lines as one line without line breaks, can anyone help me on whats going wrong here?
Here is my code:
Code:
Private Sub cmdRestore_Click()
On Error GoTo ErrHandler
Dim sSQL As String
Dim sSQL_Local As String
Dim rs As ADODB.Recordset
Dim rs_Local As ADODB.Recordset
Dim cn As ADODB.Connection
Dim sCriteria As String
If chkDIFF.Value = False Then GoTo Full
If chkDIFF.Value = True Then GoTo FullDiff
Full:
sSQL = "RESTORE DATABASE [" & txtEngID.Value & "]" & _
"FROM DISK='H:\" & txtBAK.Value & ".bak'" & _
"With RECOVERY" & _
"GO"
txtSQLStatement.Value = sSQL
GoTo Restore
FullDiff:
sSQL = "RESTORE DATABASE [" & txtEngID.Value & "]" & _
"FROM DISK='H:\" & txtBAK.Value & ".bak'" & _
"With Move 'Audit_log' to 'F:\MSSQL10.INSTANCENAME\MSSQL\DATA\" & txtBAK.Value & "_log.ldf'," & _
"NORECOVERY" & _
"GO" & _
"" & _
"RESTORE DATABASE [" & txtEngID.Value & "]" & _
"FROM DISK='H:\" & txtDIFF.Value & ".diff'" & _
"With RECOVERY" & _
"GO"
txtSQLStatement.Value = sSQL
GoTo Restore
Restore:
Set cn = New ADODB.Connection
cn.Open "ODBC;Description=Local SQL Server;DRIVER=SQL Server;SERVER=" & cmdServername.Value & "\INSTANCENAME;Trusted_Connection=Yes;"
Set rs = New ADODB.Recordset
rs.Open sSQL, cn, adOpenDynamic, adLockOptimistic
sSQL_Local = txtSQLStatement.Value
cn.Close
MsgBox "The database has been restored succesfully"
Exit_ErrHandler:
Exit Sub
ErrHandler:
MsgBox Err.Number & ": " & Err.Description
Resume Exit_ErrHandler
End Sub
Last edited: