Solved

MS Access SELECT INTO

Posted on 2008-10-22
8
2,730 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure 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 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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