Solved

MS Access SELECT INTO

Posted on 2008-10-22
8
2,709 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
 
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
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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now