473,788 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dsn-less connection copy data

Ken
How can I copy data from SQL to MS Access using dsn-less connection
and not using SQL DTS? I have this but am stuck. I just want to do
an export but can't figure out how to do a "select into". It pastes
the data in SQL instead of access. The below code will cycle but I
will have to create a table to place the data first. Is there an
easier way.

Sub getTables()
Dim cnnSQL As ADODB.Connectio n
Dim cnnMSA As ADODB.Connectio n
Dim strSQL As String
Dim rstSQL As ADODB.Recordset
Dim rstMSA As ADODB.Recordset
Dim strServer As String
Dim strDB As String
Dim i As Long
Dim cnn As ADODB.Connectio n

strServer = "northwind"
strDB = "pubs"

Set cnnSQL = New ADODB.Connectio n
Set rstSQL = New ADODB.Recordset
Set cnnMSA = CurrentProject. Connection
Set rstMSA = New ADODB.Recordset
cnnSQL.Open "Provider=sqlol edb;Data Source='" & strServer & "';Initial
Catalog='" & strDB & "';Integrat ed Security=SSPI"
strSQL = "select * from customers"

Set rstMSA = cnnSQL.Execute( strSQL)
Do While Not rstMSA.EOF
For i = 0 To rstMSA.Fields.C ount - 1
rstmsa.
'OutPuts Name and Value of each field
Debug.Print rstMSA.Fields(i ).Name & ": " & _
rstMSA.Fields(i ).Value
Next
rstMSA.MoveNext
Loop
Set cnnSQL = Nothing
Set rstSQL = Nothing

End Sub
Nov 13 '05 #1
2 2236
The following Make-Table query should make a table in your local access
database named "Customers" and import the data from the table "customers" in
catalog "pubs" in datasource "northwind" :

SELECT C1.* INTO Customers
FROM [Provider=sqlole db;Data Source='northwi nd';Initial
Catalog='pubs'; Integrated Security=SSPI].customers AS C1;
See if this works for you.

"Ken" <ni************ @hotmail.com> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
How can I copy data from SQL to MS Access using dsn-less connection
and not using SQL DTS? I have this but am stuck. I just want to do
an export but can't figure out how to do a "select into". It pastes
the data in SQL instead of access. The below code will cycle but I
will have to create a table to place the data first. Is there an
easier way.

Sub getTables()
Dim cnnSQL As ADODB.Connectio n
Dim cnnMSA As ADODB.Connectio n
Dim strSQL As String
Dim rstSQL As ADODB.Recordset
Dim rstMSA As ADODB.Recordset
Dim strServer As String
Dim strDB As String
Dim i As Long
Dim cnn As ADODB.Connectio n

strServer = "northwind"
strDB = "pubs"

Set cnnSQL = New ADODB.Connectio n
Set rstSQL = New ADODB.Recordset
Set cnnMSA = CurrentProject. Connection
Set rstMSA = New ADODB.Recordset
cnnSQL.Open "Provider=sqlol edb;Data Source='" & strServer & "';Initial
Catalog='" & strDB & "';Integrat ed Security=SSPI"
strSQL = "select * from customers"

Set rstMSA = cnnSQL.Execute( strSQL)
Do While Not rstMSA.EOF
For i = 0 To rstMSA.Fields.C ount - 1
rstmsa.
'OutPuts Name and Value of each field
Debug.Print rstMSA.Fields(i ).Name & ": " & _
rstMSA.Fields(i ).Value
Next
rstMSA.MoveNext
Loop
Set cnnSQL = Nothing
Set rstSQL = Nothing

End Sub

Nov 13 '05 #2
Sorry for posting late but it does not work. Any other ideas.

Sub subtest()
Dim strsql As String
Dim cmd As New ADODB.Command

strsql = "SELECT C1.* INTO Customers FROM [Provider=sqlole db;Data
Source='northwi nd';Initial Catalog='pubs'; Integrated
Security=SSPI].customers AS C1;"

With cmd
.ActiveConnecti on = CurrentProject. Connection
.CommandText = strsql
.CommandType = adCmdText
.Execute
End With

cmd.Close
Set cmd = Nothing
Debug.Print "done"
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

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

Similar topics

3
3178
by: McCool | last post by:
How can I get the deployment project to setup a DSN pointing to an Access DB after installation takes place? Also, is there a way to kick off a vbs script after installation takes place through the deployment project? TIA Brian
3
1801
by: emily | last post by:
Perhaps this has already been answered. If so, I apologize. I'm a newbie at this stuff. I have a DTS package to import some Visual Foxpro data. Yes, I said Visual Foxpro. :) The DTS package works beautifully when I rightclick on the package and choose "execute." And it works beautifully when I run dtsrun.... at the DOS prompt. But it doesn't work when I try to execute it with code in Query Analyzer. I've tried exec...
6
18720
by: Andi Reisenhofer | last post by:
Hallo C# folks, Somebody know how to create a ODBC DSN dynamically in c# program. Also interesting for me would be the connectionstring for an Access Database. Thinks a lot Andreas
4
11606
by: Steve Sweales | last post by:
I'm trying to find some code on how to create a DSN using C# and SQLConfigDataSource. Can anybody help me please, before I tear my hair out!! *** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
8
2845
by: DerekS | last post by:
Hi, I've been pulling my hair out trying to write a simple method to programatically create a system DSN with all parameters on a remote machine. I have ensured I have the correct permissions on that remote machine. I have also review many MSDN and codeproject.com articles. Any help would be great. Thanks, Derek
3
3492
by: Niks | last post by:
Hi, I need to connect to SQL server Database using a System DSN. Can anyone tell me how to connect to SQL Server using DSN in ASP.NET (VB.Net). Using a Try Catch block. Does anyone know how to create a "filename.DSN" file. I know how to create a system DSN, but my N/W admin has asked me to create a DSN file to send him. which would be a file name with ".DSN" extension, so that he can place it on the server.
14
2286
by: kdv09 | last post by:
Hi! I'm looking for some help in fixing my screwup: I've got C++ app which reads MDB database, using MFC CDatabase and CRecordset derived classes. I had it working OK on development PC (Win XP SP2) with MS Access 2000 installed (the app itself does not use MS Access). I moved the app on another PC (also Win XP SP2) without MS Access. After some poking around I've figured out that the app does not work because DSN it is using was not...
0
1291
by: Neo | last post by:
Hello All, ODBCAD32.exe launches DSN Setup. But then I have to select DSN and click configure to configure DSN. Is there any way, I could invoke configuration dialog box for particular DSN straight without lanuching ODBCAD32.exe? I am trying to write code to create DSN, if it is not present. I was wondering, if DSN required isn't present, I could use the built-in configure DSN box to take information from user. In that way, user will
0
3646
by: senthildb2 | last post by:
Hi there, I want to create DSN for DB2 database through my VB application. I have installed DB2 v8.2 with FixPack6.0 ESE. (The actual version shown in Control Center is DB2 V8.1.13.193) The problem is that VB application crashes without reporting any error. DSN is not getting created. But I am able to create DSN through Control Panel. Here is the code snippet to create DSN
4
3683
by: bytesbytes | last post by:
Hi, Im using VB6.0, Crystal report 10 and MSaccess Database. I was using Crystal report 6 and later upgraded to CR10. In VB6 i used DSN like .Connect = "DSN=DBName" & ";UID=admin;PWD=;" Now in CR10 i have created reports without using DSN in VB. Can any help how to use DSN in VB6.0 with CR10 or is there any method so that i no need to use DSN in the above said requirements. The code used for CR10 is Set Report = Appl.OpenReport(App.Path...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.