The backup set holds a backup of a database other than the existing 'ControlEV54_Test' database.
RESTORE DATABASE is terminating abnormally.
Changed database context to 'ControlEV54'.
ต้องแก้ตรงไหนค่ะ help me plz. Code (VB.NET)
Imports System.Data.SqlClient
Imports System.IO
Imports System.Data
Public Class Form2
Dim objConn As SqlConnection
Dim objCmd As SqlCommand
Dim strConnString As String
Dim cmdConnString As String
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strConnString = "Data Source=PROGRAMMER06-PC;Initial Catalog=ControlEV54_Test;Integrated Security=True"
objConn = New SqlConnection(strConnString)
objConn.Open()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If objConn.State = ConnectionState.Open Then
'objCmd = New SqlCommand("DROP DATABASE ControlEV54_Test", objConn)
'objCmd.ExecuteNonQuery()
objCmd = New SqlCommand("ALTER DATABASE ControlEV54_Test SET SINGLE_USER", objConn)
objCmd.ExecuteNonQuery()
'objConn.Close()
objCmd = New SqlCommand("USE ControlEV54 RESTORE DATABASE ControlEV54_Test FROM DISK = 'D:\backup_nid\mybackup.bak'", objConn)
objCmd.ExecuteNonQuery()
'objConn.Close()
MessageBox.Show("restore สำเร็จ")
objCmd = New SqlCommand("ALTER DATABASE ControlEV54_Test SET MULTI_USER", objConn)
objCmd.ExecuteNonQuery()
objConn.Close()
Else
Me.lblText.Text = "SQL Server Connect Failed"
End If
End Sub
End Class
CREATE TABLE ตารางที่จะสร้าง SELECT * FROM ตารางที่ต้องการcopy
แต่ทำใน sql2008 ไม่ได้อ่ะค่ะ T_T
Date :
2013-06-18 16:06:42
By :
nunidnaja
No. 7
Guest
ขอให้โชคดีครับ
Code
Public Shared Function RunSQLScript() As Boolean
Dim suc As Boolean = False
Dim s As New StringBuilder()
Dim scConnection As New ServerConnection(New SqlConnection() With {
.ConnectionString = "Data Source=ServerName;Initial Catalog=xDB;User ID=sa;Password=1234"
})
Dim sqlServer As New Microsoft.SqlServer.Management.Smo.Server(scConnection)
sqlServer.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql
'******************************
'ควรจะอ่านค่ามาจากไฟล์ yourFiles123456.sql หรือ Text Files xxx.text
'******************************
s.Append("USE yourDB")
s.Append("GO")
s.Append("BEGIN TRANSACTION")
s.Append("SET QUOTED_IDENTIFIER ON")
s.Append("SET ARITHABORT ON")
s.Append("SET NUMERIC_ROUNDABORT OFF")
s.Append("SET CONCAT_NULL_YIELDS_NULL ON")
s.Append("SET ANSI_NULLS ON")
s.Append("SET ANSI_PADDING ON")
s.Append("SET ANSI_WARNINGS ON")
s.Append("COMMIT")
s.Append("BEGIN TRANSACTION")
s.Append("GO")
s.Append("ALTER TABLE dbo.yourTable ADD yourNewColumn varchar(100) NULL")
s.Append("GO")
s.Append("ALTER TABLE dbo.xTable SET (LOCK_ESCALATION = TABLE)")
s.Append("GO")
s.Append("COMMIT")
Try
sqlServer.ConnectionContext.ExecuteNonQuery(s.ToString())
Catch ex As Exception
'TO DO
End Try
Return suc
End Function