473,408 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Create Linked Table

I am trying to create a VB.NET Windows application to move some data from a
local Access DB table to a table in a SQL Server. The approach I am trying
is to open an OLEDB connection to the local Access DB and then add a Linked
Table pointing to the table on the SQL Server and then run an "Insert Into
(linked table)" query to add the new rows.

I am having a problem getting the syntax to add that linked table to my
local Access DB. When I used to create a LinkedTable to another Access DB I
used to use the code below but I haven't been able to find the correct
syntax to make linked table from SQL Server.

Pointers to any helpful information will be much appreciated.

Wayne
============== Code =================
Public Sub AddLink()
Dim objCat As ADOX.Catalog
Dim objTbl As ADOX.Table
objCat = New ADOX.Catalog
objTbl = New ADOX.Table

objCat.ActiveConnection = myConn
objTbl.Name = "DC"
objTbl.ParentCatalog = objCat
objTbl.Properties("Jet OLEDB:Create Link") = True
objTbl.Properties("Jet OLEDB:Link Provider String") = "MS
Access;DATABASE=" & strLocalDBPath
objTbl.Properties("Jet OLEDB:Remote Table Name") = "DC"

objCat.Tables.Append(objTbl)
objCat.Tables.Refresh()

objCat = Nothing
objTbl = Nothing
End Sub
========================================
Nov 21 '05 #1
4 8086
On Mon, 7 Mar 2005 07:40:02 -0700, "Wayne Wengert" <wa***************@wengert.com> wrote:

¤ I am trying to create a VB.NET Windows application to move some data from a
¤ local Access DB table to a table in a SQL Server. The approach I am trying
¤ is to open an OLEDB connection to the local Access DB and then add a Linked
¤ Table pointing to the table on the SQL Server and then run an "Insert Into
¤ (linked table)" query to add the new rows.
¤
¤ I am having a problem getting the syntax to add that linked table to my
¤ local Access DB. When I used to create a LinkedTable to another Access DB I
¤ used to use the code below but I haven't been able to find the correct
¤ syntax to make linked table from SQL Server.
¤
¤ Pointers to any helpful information will be much appreciated.
¤
¤ Wayne
¤
¤
¤ ============== Code =================
¤ Public Sub AddLink()
¤ Dim objCat As ADOX.Catalog
¤ Dim objTbl As ADOX.Table
¤ objCat = New ADOX.Catalog
¤ objTbl = New ADOX.Table
¤
¤ objCat.ActiveConnection = myConn
¤ objTbl.Name = "DC"
¤ objTbl.ParentCatalog = objCat
¤ objTbl.Properties("Jet OLEDB:Create Link") = True
¤ objTbl.Properties("Jet OLEDB:Link Provider String") = "MS
¤ Access;DATABASE=" & strLocalDBPath
¤ objTbl.Properties("Jet OLEDB:Remote Table Name") = "DC"
¤
¤ objCat.Tables.Append(objTbl)
¤ objCat.Tables.Refresh()
¤
¤ objCat = Nothing
¤ objTbl = Nothing
¤ End Sub
¤ ========================================
¤

See if the following helps:

Sub CreateAttachedSQLTableWithADOX()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection

Try

ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

ADOXTable.ParentCatalog = ADOXCatalog
ADOXTable.Name = "Customers"
ADOXTable.Properties("Jet OLEDB:Remote Table Name").Value = "Customers"
ADOXTable.Properties("Jet OLEDB:Link Provider String").Value = "ODBC;Driver={SQL
Server};" & _
"Server=(local);" & _
"Database=Northwind;" & _
"Uid=sa;" & _
"Pwd="
ADOXTable.Properties("Jet OLEDB:Create Link").Value = True
ADOXCatalog.Tables.Append(ADOXTable)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #2
Paul;

Thanks for the complete example. That really helps. I tried adapting the
example to my data (changed to the IP address of the SQL server and entered
the correct database, AID and PW but it keeps failing saying that it cannot
connect to my server. The "Driver={SQLServer};" is a constant, right?

Wayne

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:89********************************@4ax.com...
On Mon, 7 Mar 2005 07:40:02 -0700, "Wayne Wengert" <wa***************@wengert.com> wrote:
¤ I am trying to create a VB.NET Windows application to move some data from a ¤ local Access DB table to a table in a SQL Server. The approach I am trying ¤ is to open an OLEDB connection to the local Access DB and then add a Linked ¤ Table pointing to the table on the SQL Server and then run an "Insert Into ¤ (linked table)" query to add the new rows.
¤
¤ I am having a problem getting the syntax to add that linked table to my
¤ local Access DB. When I used to create a LinkedTable to another Access DB I ¤ used to use the code below but I haven't been able to find the correct
¤ syntax to make linked table from SQL Server.
¤
¤ Pointers to any helpful information will be much appreciated.
¤
¤ Wayne
¤
¤
¤ ============== Code =================
¤ Public Sub AddLink()
¤ Dim objCat As ADOX.Catalog
¤ Dim objTbl As ADOX.Table
¤ objCat = New ADOX.Catalog
¤ objTbl = New ADOX.Table
¤
¤ objCat.ActiveConnection = myConn
¤ objTbl.Name = "DC"
¤ objTbl.ParentCatalog = objCat
¤ objTbl.Properties("Jet OLEDB:Create Link") = True
¤ objTbl.Properties("Jet OLEDB:Link Provider String") = "MS
¤ Access;DATABASE=" & strLocalDBPath
¤ objTbl.Properties("Jet OLEDB:Remote Table Name") = "DC"
¤
¤ objCat.Tables.Append(objTbl)
¤ objCat.Tables.Refresh()
¤
¤ objCat = Nothing
¤ objTbl = Nothing
¤ End Sub
¤ ========================================
¤

See if the following helps:

Sub CreateAttachedSQLTableWithADOX()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection

Try

ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

ADOXTable.ParentCatalog = ADOXCatalog
ADOXTable.Name = "Customers"
ADOXTable.Properties("Jet OLEDB:Remote Table Name").Value = "Customers" ADOXTable.Properties("Jet OLEDB:Link Provider String").Value = "ODBC;Driver={SQL Server};" & _
"Server=(local);" & _ "Database=Northwind;" & _ "Uid=sa;" & _
"Pwd="
ADOXTable.Properties("Jet OLEDB:Create Link").Value = True
ADOXCatalog.Tables.Append(ADOXTable)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #3
Paul;

When I copied your example I dropped the space between "SQL" and "Server".
That broke it! I think I have it working now. Thanks for the help!

Wayne

"Paul Clement" <Us***********************@swspectrum.com> wrote in message
news:89********************************@4ax.com...
On Mon, 7 Mar 2005 07:40:02 -0700, "Wayne Wengert" <wa***************@wengert.com> wrote:
¤ I am trying to create a VB.NET Windows application to move some data from a ¤ local Access DB table to a table in a SQL Server. The approach I am trying ¤ is to open an OLEDB connection to the local Access DB and then add a Linked ¤ Table pointing to the table on the SQL Server and then run an "Insert Into ¤ (linked table)" query to add the new rows.
¤
¤ I am having a problem getting the syntax to add that linked table to my
¤ local Access DB. When I used to create a LinkedTable to another Access DB I ¤ used to use the code below but I haven't been able to find the correct
¤ syntax to make linked table from SQL Server.
¤
¤ Pointers to any helpful information will be much appreciated.
¤
¤ Wayne
¤
¤
¤ ============== Code =================
¤ Public Sub AddLink()
¤ Dim objCat As ADOX.Catalog
¤ Dim objTbl As ADOX.Table
¤ objCat = New ADOX.Catalog
¤ objTbl = New ADOX.Table
¤
¤ objCat.ActiveConnection = myConn
¤ objTbl.Name = "DC"
¤ objTbl.ParentCatalog = objCat
¤ objTbl.Properties("Jet OLEDB:Create Link") = True
¤ objTbl.Properties("Jet OLEDB:Link Provider String") = "MS
¤ Access;DATABASE=" & strLocalDBPath
¤ objTbl.Properties("Jet OLEDB:Remote Table Name") = "DC"
¤
¤ objCat.Tables.Append(objTbl)
¤ objCat.Tables.Refresh()
¤
¤ objCat = Nothing
¤ objTbl = Nothing
¤ End Sub
¤ ========================================
¤

See if the following helps:

Sub CreateAttachedSQLTableWithADOX()

Dim ADOXTable As New ADOX.Table
Dim ADOXCatalog As New ADOX.Catalog
Dim ADOConnection As New ADODB.Connection

Try

ADOConnection.Open("Provider=Microsoft.Jet.OLEDB.4 .0;" & _
"Data Source=e:\My Documents\db1.mdb;" & _
"Jet OLEDB:Engine Type=4;")

ADOXCatalog.ActiveConnection = ADOConnection

ADOXTable.ParentCatalog = ADOXCatalog
ADOXTable.Name = "Customers"
ADOXTable.Properties("Jet OLEDB:Remote Table Name").Value = "Customers" ADOXTable.Properties("Jet OLEDB:Link Provider String").Value = "ODBC;Driver={SQL Server};" & _
"Server=(local);" & _ "Database=Northwind;" & _ "Uid=sa;" & _
"Pwd="
ADOXTable.Properties("Jet OLEDB:Create Link").Value = True
ADOXCatalog.Tables.Append(ADOXTable)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
ADOConnection.Close()
End Try

End Sub
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)

Nov 21 '05 #4
On Mon, 7 Mar 2005 12:14:55 -0700, "Wayne Wengert" <wa***************@wengert.com> wrote:

¤ Paul;
¤
¤ Thanks for the complete example. That really helps. I tried adapting the
¤ example to my data (changed to the IP address of the SQL server and entered
¤ the correct database, AID and PW but it keeps failing saying that it cannot
¤ connect to my server. The "Driver={SQLServer};" is a constant, right?
¤
¤ Wayne

Yes, you shouldn't need to change the Driver parameter. I'm running a local version of SQL Server so
you would probably need to change that parameter.

You may want to check the below link for other variations:

http://www.able-consulting.com/MDAC/...erForSQLServer
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: js | last post by:
I need to create a relationship between a local table and tables on a linked server. I used the design table wizard and selected the relationship property wizard. In the reslationship property...
0
by: Chris Powell | last post by:
I am using Excel/Access 2000 and have two large Excel files (25,000 rows each) that I wish to create linked tables in Access rather than importing into Access. The two source Excel files change...
4
by: intl04 | last post by:
How do I create a data input form in Access that is external to the Access database to which it's connected (if that's possible, which I believe it is)? For example, if someone clicks on an Access...
3
by: G rumpy O ld D uffer | last post by:
This is probably a 'Low-Level' question to all the ACCESS experts but I've only been using ACCESS for a couple of weeks. I've been given 30+ (and counting) separate 'Weekly' Databases which all...
3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
6
by: skgolden | last post by:
My husband and I own a small temporary labor company and deal with 4 major clients (A,B,C & D), each of which has about 2 dozen units in our tristate area that we deal with (ie, Company A, units...
1
by: deko | last post by:
DoCmd.CopyObject copies data, but I only need structure. I'm trying to clone several tables in my Access 2003 mdb. The goal is to link to a series of Excel spreadsheets and then run various...
1
by: David | last post by:
I am hopeing someone can help me with this as I have struggled over the last few days with it. I have a make table query which I want to use to split the table up into seperate tables which are...
15
by: Killer42 | last post by:
Hi all. Ok, I'm using VB6 but I think the answer to this (if there is one) is more likely to be found in the Access forum. I have a situation where I've got tens of millions of records, spread...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.