Solved

MS Access SELECT INTO

Posted on 2008-10-22
8
2,720 Views
Last Modified: 2013-11-20
I have two databases. Lets call the first DB1 and the second DB2.

I am connecting to those databases in MFC.

I am trying to copy one table from DB2 to DB1. Lets call it Table1. Lets call the new table Table2.

I use ExecuteSQL() function of CDatabase calling it from the first Database object.

m_db1.ExecuteSQL(_T(SELECT * INTO Table2 FROM Table1 IN 'Data\\DB2.mdb'));

Well everything is working perfectly. But I am going to put passwords on those two databases. My question is: How do I provide the passwords in the SQLString?
0
Comment
Question by:Choklander
  • 4
  • 2
  • 2
8 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22781235
You should be able to open a connection to the database using the password, then execute your SQL and close the connection.

/gustav
0
 

Author Comment

by:Choklander
ID: 22781266
Well how do I provide their passwords ? I open db1 and from it's object I call the ExeciteSQL. But in that SQLString I need to provide the password for db2. How do I provide it? Can you show me on the SQLString I have provided you with?
0
 
LVL 11

Accepted Solution

by:
datAdrenaline earned 500 total points
ID: 22781336
I will let you modify the details of the SQL statement to fit your needs ... but generically an SQL Statement that selects records from a db password protected source will take the form:

SELECT * FROM YourTable IN '' [<connect string>]
{Note: the '' is two single quotes indicating a ZLS }

... Or ...

SELECT * FROM [<connect string>].YourTable

Where <connect string> is the text you would see for the .Connect property of a linked table.

Examples of SELECT statements that connect to password protected data that is in JET format (MDB/ACCDB)

SELECT * FROM tblAreas IN '' [;Database=C:\Temp\MyAreas.mdb;pwd=mypwd]

... Or ...

SELECT * FROM [;Database=C:\Temp\MyAreas.mdb;pwd=mypwd].tblAreas

.....

I am unaware of .ExecuteSQL() function, so I can only assume that your SQL statement will be executed by the JET db engine ... if so, you would keep your SQL statement as its written on the left of the IN clause, then modify the IN clause to a ZLS, then append your <connect string> with a PWD ... probably something like this.

SELECT * INTO Table2 FROM Table1 IN '' [;Data\\DB2.mdb;pwd=yourpassword]

REMEMBER ... the '' immediate to the right of the IN is two single quotes! ...

Hope that helps!
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 11

Assisted Solution

by:datAdrenaline
datAdrenaline earned 500 total points
ID: 22781348
Sorry ...
I forget the 'Database=' identifier in the <connect string> ... but ... it will probably work without it ... if not give this a go ...

SELECT * INTO Table2 FROM Table1 IN '' [;Database=Data\\DB2.mdb;pwd=yourpassword]
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22781448
> I need to provide the password for db2. How do I provide it?

By opening a connection til db2 too including the password.

I know nothing about MFC so I cannot provide code but this method is generic.

/gustav
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 22781847
Hello Cactus ...

The posters question indicates that the desire is to have the pwd (assuming its a database password) in the SQL statement ...

>> How do I provide the passwords in the SQLString? <<
0
 

Author Comment

by:Choklander
ID: 22782421
Thanks a lot. The problem with my string was that I put my database source in the '' single quotes. Nice explanation top grade. Have fun.
0
 
LVL 11

Expert Comment

by:datAdrenaline
ID: 22783187
You're most welcome! ...
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question