Solved

MS Access SELECT INTO

Posted on 2008-10-22
8
2,700 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
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.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

743 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

9 Experts available now in Live!

Get 1:1 Help Now