Click here to Skip to main content
16,018,318 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello, I want to make a backup of a sql table in dll file .

waiting for your help

thank you in advance
Posted
Comments
G-code101 5-Feb-14 4:20am    
Firstly what have you done so far? supply a snippet so I can help

This might help: Backing up an SQL Database in C#[^] - it's in C#, but the code is pretty obvious.
 
Share this answer
 
Comments
G-code101 5-Feb-14 5:18am    
What I'm thinking is he wants to statically save the data in dll as one would doing it in an xml/xaml file and use the dll as a basis of the database...I might be wrong
OriginalGriff 5-Feb-14 5:23am    
It's possible - but nasty.
Wait and see what he come back with I guess...
G-code101 5-Feb-14 5:47am    
I posted a solution on just backing up the database completely to dll but getting confused is pretty easy... My only question would be why make life so difficult?????
anis_sg 11-Feb-14 4:17am    
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
OriginalGriff 11-Feb-14 4:42am    
No - bad idea. A DLL is supposed to be executable, and saving tables as that is not a good idea.
If you want unobvious and unmodifiable, just save it with a "random" extension (".STB" or similar perhaps) and encrypt it. That's simple, and difficult to undo without the source code and decryption key.
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

VB
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
 
Share this answer
 
v4
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
 
Share this answer
 
I'm failing to understand how the data size is limited in a SQL 2008 database (WHAT SIZE IS YOUR DATABASE? 10GB + ???) If so then that explains it... I have created databases that exceed 1GB up to 6GB but the database consisted of files and such... Anyway save the table data using a class containing a List object, then use xml serializer to save it as a file with your own extension with an encryption... That might work

I added one of my unfinished projects on dropbox that will give you the idea...

DROP BOX LINK TO PROJECT[^]

But bare in mind if and when your data file becomes huge the slower it will respond to retrieval of data!!!
 
Share this answer
 
v3
Comments
anis_sg 11-Feb-14 7:24am    
thank you for your answer but I can't access the files in Dropbox, please resend me the link
G-code101 11-Feb-14 9:03am    
I HATE IT WHEN MY LINKS DO THIS!!!!! They hardly seem to insert correctly ...
Try this link^

THINGS YOU WILL NEED...

.Net 4.0
VS 2012

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900