Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2006, 10:01 AM
Registered User
 
Join Date: May 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default install database on SQL Server

 I want to install a MS Access database on MS SQL Server in VB6.
Until now I managed to install database structure using T-SQL script.
Now I need to populate the DB on server with data from the original .mdb file; I need a colection of all (user)tables existing in the DB, and then use some kind of
INSERT INTO table1
  SELECT * FROM table2;
table1 being on server DB
table2 being on local DB
can u help me??

 
Old September 4th, 2006, 12:06 AM
Authorized User
 
Join Date: Aug 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default


To decap_itate:

Try using the upsizing wizard. It is an excellent tool of creating an SQL Server database from an existing Access database. It works well for me.


JFe'

 
Old October 1st, 2006, 06:31 PM
Authorized User
 
Join Date: Aug 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I hope these code segments will help.
---------------
Option Explicit

Dim rsVirtual As Recordset 'Declare a virtual recordset

Private Sub Form_Activate()
--
--
createVirtual
readTable1
transferToTable2
--
--
End Sub

Private Sub createVirtual()
'-------------------------------
' this process creates the
' virtual recordset. a virtual
' recordset is not connected to
' the database, nor is it a part
' of the database. it just serves
' as the medium of transfer.
' use the same record structure as
' that of the source and target
' tables.
'--------------------------------
Set rsVirtual = New Recordset
With rsVirtual.Fields
.Append "<recordset column/field name>",type, size
--
--
End With
rsVirtual.Open
End Sub


Private Sub readTable1()
'---------------------------------
' this process reads table 1 which
' is the ms access table which
' serves as the source of records
' to be transferred. the virual
' recordset receives the records from
' the access table.
' make sure that you open a connection
' to your access database.
'---------------------------------
Dim dbCon As New ADODB.Connection
Dim rsRec As New ADODB.Recordset
Dim strSQL As String

dbCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                         "Data Source = <Access database pathname>"
dbCon.Open
dbCon.CursorLocation = adUseServer

strsql = "SELECT * FROM <table1>"
rsRec.Open strSQL, dbCon, adOpenKeyset, adLockOptimistic

rsRec.MoveFirst
While not rsRec.EOF
With rsVirtual
      .AddNew
      .Fields(<1st column name of virtual recordset>) = _
      rsRec(<corresponding column name from the SQL table>)
      '-- continue until the last colum/field of the tables
      .Update
End With
rsRec.MoveNext
Wend
'-- now close the connection with the Access database --
set rsRec=nothing
set dbCon=nothing
End Sub


Private Sub transferToTable2()
'------------------------------------
' this process transfers the records
' from table 1 which temporarily
' reside in the virtual recordset
' you must establish a connection
' to the target SQL Server database
'-----------------------------------
Dim dbCon As New ADODB.Connection
Dim rsRec As New ADODB.Recordset
Dim strSQL As String

dbCon.ConnectionString = "<the SQL database connection string
                          database pathname>"
dbCon.Open
dbCon.CursorLocation = adUseServer

strsql = "SELECT * FROM table2 WHERE 1=2"
rsRec.Open strSQL, dbCon, adOpenKeyset, adLockOptimistic

rsVirtual.MoveFirst
While not rsVirtual.EOF
With rsRec
     .AddNew
     .Fields(<1st column name of SQL Server table>) = _
         rsVirtual _
             (<corresponding column name from the Access table>)
     '-- continue until the last colum/field of the tables
     .Update
End With
rsVirtual.MoveNext
Wend
'-- now close the connection with the SQL Server database --
set rsRec=nothing
set dbCon=nothing
End Sub


The above uses an intermediate table which I called the virtual recordset (rsVirtual).

It should make things easy for the transfer.

I hope it will be of help.

Jorge





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to install SQL Server 2005 muellmk SQL Server 2005 0 October 8th, 2007 07:33 AM
Unable to Install SQL Server 2005 [email protected] SQL Server 2005 3 September 15th, 2006 11:00 AM
install database on SQL Server decap_itate VB Databases Basics 0 May 2nd, 2006 10:02 AM
Failed to install SQL Server 2005 shalim Visual Studio 2005 1 January 16th, 2006 07:37 PM
Can we install SQL Server on WinXP Pro? dotnetwhizkid SQL Server 2000 6 August 26th, 2003 03:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.