在dll中保存SQL表 [英] Save SQL Table in dll

查看:84
本文介绍了在dll中保存SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我想在dll文件中备份一个sql表。



等待你的帮助



提前谢谢

hello, I want to make a backup of a sql table in dll file .

waiting for your help

thank you in advance

推荐答案

这可能会有所帮助:用C#备份SQL数据库 [ ^ ] - 它在C#中,但代码非常明显。
This might help: Backing up an SQL Database in C#[^] - it's in C#, but the code is pretty obvious.


基础知识您需要的...程序集可以在c:\program files \ Microsoft SQL Server \XXX \ SDK \Assemblies \ ...(XXX =您安装的SQL Server版本)中找到。备份数据库<不是单个表



Basics what you need... The assemblies can be found in c:\program files\Microsoft SQL Server\XXX\SDK\Assemblies\... (XXX = Version of your SQL Server installed.) ONLY BACKS UP DATABASE< NOT A SINGLE TABLE

Imports System.IO
Imports Microsoft.SqlServer.Management
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Server
Imports Microsoft.SqlServer.Management.Common
Imports Microsoft.SqlServer.Management.Smo.Agent
Imports Microsoft.SqlServer.Management.Smo.Broker
Imports Microsoft.SqlServer.Management.Smo.Mail
Imports Microsoft.SqlServer.Management.Smo.RegisteredServers
Imports Microsoft.SqlServer.Management.Smo.Wmi

Private Class BackupDatabase
   Public Sub CreateBackup()            
            ' Create a new Instance of Backup.            
            Dim bckupDatabase As New Backup
            ' Create an Instance of the action that needs to run.
            bckupDatabase.Action = BackupActionType.Database
            ' Create a new Instance of the Server where the database is located
            Dim myServer As Server = New Server("YOURSERVERNAMEHERE")
            ' Set your database to the database which you want to backup.
            Dim myDatabase As Database = myServer.Databases("YOURDATABASENAME")
            ' Sets the current database to be used by the BackupActionType.
            bckupDatabase.Database = myDatabase.Name
            ' This I used with a folder browser dialog and to verify when the text box contains
            ' C:\ or C:\Folder so it automatically sets the slash correctly You could remove
            ' method and replace it with your own if you want the location statically. 
            Dim int As Integer = txtLocation.Text.Length

            If int = 3 Then
                bckupDatabase.Devices.AddDevice(txtLocation.Text + "\BACKUPDATABASENAME.dll", DeviceType.File)
            ElseIf int > 3 Then
                bckupDatabase.Devices.AddDevice(txtLocation.Text + "BACKUPDATABASENAME.dll", DeviceType.File)
            End If

            bckupDatabase.BackupSetName = "TYPE DATABASE BACKUP NAME HERE"
            bckupDatabase.BackupSetDescription = "TYPE DATABASE BACKUP DESCRIPTION (eg. Full Bacup) HERE"
            bckupDatabase.Initialize = False

            AddHandler bckupDatabase.PercentComplete, AddressOf CompletionStatusInPercent
            AddHandler bckupDatabase.Complete, AddressOf Backup_Completed

            bckupDatabase.SqlBackup(myServer)
        Catch ex As Exception
            MessageBox.Show(ex.Message & ex.StackTrace)
        End Try
    End Sub

    Private Sub CompletionStatusInPercent(sender As Object, args As PercentCompleteEventArgs)
        txtStatusLog.Text = String.Format("Percent completed: {0}%.", args.Percent)
    End Sub

    Private Sub Backup_Completed(sender As Object, args As ServerMessageEventArgs)
        txtStatusLog.Text = txtStatusLog.Text & vbNewLine & ("Success...Backup completed.")
        txtStatusLog.Text = txtStatusLog.Text & vbNewLine & (args.Error.Message)
    End Sub
End Class


首先,我非常感谢你的答案。



更清楚,我会解释我的需要,目前我正在使用sql server express(数据大小有限),我必须备份一个大的表来释放空间,我想把它保存为DLL来禁止可见性和修改



等待您的提案
First of all, I want to thank you very much for your answers.

to be more clear, I'll explain my need, currently I'm using sql server express (data size is limited), I have to make a backup of a table that will be large to free up space, I thought to save it as a DLL to prohibit visibility and modification

waiting for your proposals


这篇关于在dll中保存SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆