11-12-22, 02:27 PM
السلام عليكم
اخوتي الاعضاء الكرام
اريد اجراء ضغط قاعدة البيانات بعد اخذ النسخة الاحتياطية
والكود المستخدم في النسخ كالاتي:_
====================================================================
Dim dt As String
dt = Format(Now, "dd-MM-yyyy____hh-mm-ss-tt")
Dim sfd As New SaveFileDialog
sfd.Filter = "SQL Backup File |*.bak"
sfd.Title = "نسخ قاعدة البيانات"
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim con As SqlClient.SqlConnection = New SqlConnection("Data Source=Mohammed\SQL_2019_KF;Initial Catalog=DB_SALE;USER ID=sa; Password=123456")
Dim backupcmd As New SqlCommand()
With backupcmd
.Connection = con
.CommandText = " use master BACKUP DATABASE [DB_SALE] TO DISK = N'" & sfd.FileName & "' WITH NOFORMAT, INIT, " _
& " Name = N'DataBaseName-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
Try
If con.State = ConnectionState.Closed Then con.Open()
Me.Cursor = Cursors.WaitCursor
.ExecuteNonQuery()
Me.Cursor = Cursors.Default
MessageBox.Show("تم انشاء نسخه احتياطية من قاعدة البيانات ", "")
Catch ex As Exception
Me.Cursor = Cursors.Default
If con.State = ConnectionState.Open Then con.Close()
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End With
Else
Exit Sub
End If
============================================================================
ارجو المساعدة حتى بفكره
اخوتي الاعضاء الكرام
اريد اجراء ضغط قاعدة البيانات بعد اخذ النسخة الاحتياطية
والكود المستخدم في النسخ كالاتي:_
====================================================================
Dim dt As String
dt = Format(Now, "dd-MM-yyyy____hh-mm-ss-tt")
Dim sfd As New SaveFileDialog
sfd.Filter = "SQL Backup File |*.bak"
sfd.Title = "نسخ قاعدة البيانات"
If sfd.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim con As SqlClient.SqlConnection = New SqlConnection("Data Source=Mohammed\SQL_2019_KF;Initial Catalog=DB_SALE;USER ID=sa; Password=123456")
Dim backupcmd As New SqlCommand()
With backupcmd
.Connection = con
.CommandText = " use master BACKUP DATABASE [DB_SALE] TO DISK = N'" & sfd.FileName & "' WITH NOFORMAT, INIT, " _
& " Name = N'DataBaseName-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
Try
If con.State = ConnectionState.Closed Then con.Open()
Me.Cursor = Cursors.WaitCursor
.ExecuteNonQuery()
Me.Cursor = Cursors.Default
MessageBox.Show("تم انشاء نسخه احتياطية من قاعدة البيانات ", "")
Catch ex As Exception
Me.Cursor = Cursors.Default
If con.State = ConnectionState.Open Then con.Close()
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End With
Else
Exit Sub
End If
============================================================================
ارجو المساعدة حتى بفكره