Solved

MS Access SELECT INTO

Posted on 2008-10-22
8
2,722 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 50

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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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 50

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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…
Viewers will learn how the fundamental information of how to create a table.

733 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