Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am trying to develop a software which required to access our central SQL server database which is not all the time available because of poor connectivity. so I want to copy some tables (some of them have lots of records > 40,000) form online SQL server to my local Access database on the click of a button.

The question I am having trouble answering is: What would be the most efficient way to
copy tables or entire database to the local Access database

Does anyone have any example code that would show me how to do this effectively. I don't care about overwriting the local data. That would be okay in this case.
Posted
Comments
Sergey Alexandrovich Kryukov 7-Dec-11 2:22am    
I wonder why such a dirty approach would be ever needed..?
--SA
[no name] 8-Dec-11 5:13am    
According to me this is the only way I can do this job completed since the application is distributed in many cities and users are not good in computer. so I cannot use SQL server locally. Can u suggest me any better way to do this?

If it is Microsoft SQL Server ( as written "our central SQL server" ), the best way is to use replication of data.

See Types of Replication Overview[^] with MS SQL Server.

It is very reliable way to distribute SQL data over many locations.
 
Share this answer
 
VB
Try
            
            Dim sDBFile As String = "SERVER PATH"
            Dim sBackUpFile As String = "D:\BACKUP"
            If Not System.IO.Directory.Exists(sBackUpFile) Then
                System.IO.Directory.CreateDirectory(sBackUpFile)
            End If
            '  a = Format$(Now.Date, "ddMMyyyy")
            b = a
            c1 = Now.ToLongTimeString
            d = c1
            c1 = c1.Replace(":", "")
            c1 = c1.Replace(" ", "")
            d = c1
            sBackUpFile &= "\ABC.mdb"
            'First check the file u want to compact exists or not
            If File.Exists(sDBFile) Then
                Dim db As New OleDb.OleDbConnection
                'CompactDatabase has two parameters, creates a copy of compact DB at the Destination path
                FileCopy(sDBFile, sBackUpFile)
            End If
            'restore the original file from the compacted file
            If File.Exists(sBackUpFile) Then
                File.Delete(sBackUpFile)
                File.Copy(sDBFile, sBackUpFile, True)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        MsgBox("Backup of INTELPAT database was backedUp successfully !" & vbCrLf & "This Backup can bi found in D:\BACKUP\ABC_today'sdate.mdb ", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, )



This code will copy entire database....:)
 
Share this answer
 
Comments
[no name] 7-Dec-11 22:52pm    
Please specify datatype of "file"
Another way to transfer data between two servers is to use Linked Servers. For more information, see: http://msdn.microsoft.com/en-us/library/ms188279.aspx[^].

Also, if possible, consider using SQL Server instead of Access. That would make thing much more simpler. You can use a lightweight editions such as SQL Server CE etc.
 
Share this answer
 

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