473,657 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Join between a local table and an external one, using connect string?

Zwoker
66 New Member
Hi all,

I am accessing data from an Oracle database via a connect string.

I got into the situation where I wanted to write my SQL select statement to do a join between a local table sitting in my MS Access (2003) database, and an external Oracle table. But I realised I had no idea how to write the SQL. It appears that the whole SQL command gets passed to Oracle, not giving me any visibility to my local tables, is that correct?

I know that if I declare the Oracle tables as external tables in the MS Access environment (rather than use a connect string), I can write VBA code that transparently treats them as local tables for SQL syntax purposes, so I could code SQL that way. But security constraints imposed on me don't allow me to do that - each user of the final MDE would need their own Oracle security logins.

I call my SQL statements using the following style of VBA. If there is another VBA command I should be using, or if there is valid SQL syntax to do what I want, then please let me know.

Expand|Select|Wrap|Line Numbers
  1. Set InitialRst = New ADODB.Recordset
  2. InitialRst.Open SQLstring, connForDB, adOpenStatic, adLockReadOnly
As you would expect the SQLstring contains my SQL command, and the connForDB is the connection object to the Oracle database.

Thanks in advance for any help or suggestions.
Mar 26 '08 #1
15 6643
FishVal
2,653 Recognized Expert Specialist
Hi, Zwoker.

..... But I realised I had no idea how to write the SQL. It appears that the whole SQL command gets passed to Oracle, not giving me any visibility to my local tables, is that correct? ...
To the best of my knowledge it = True.

....
I know that if I declare the Oracle tables as external tables in the MS Access environment (rather than use a connect string), I can write VBA code that transparently treats them as local tables for SQL syntax purposes, so I could code SQL that way. But security constraints imposed on me don't allow me to do that - each user of the final MDE would need their own Oracle security logins.
....
You may link external table dynamically via code just after a user has looged into the front-end (I hope you have a copy of front-end for each user session).

Refer to Access help concerning DAO.Database.Cr eateTableDef method and DAO.TableDefs collection (particularly Append method).
Exploring DAO.TableDef class will give you much useful information too.

Regards,
Fish
Mar 26 '08 #2
Zwoker
66 New Member
Refer to Access help concerning DAO.Database.Cr eateTableDef method and DAO.TableDefs collection (particularly Append method).
Exploring DAO.TableDef class will give you much useful information too.
Hi,

If I understand you (and the quick look I've had at the help for CreateTableDefs ), are you saying that I can use that to create a link to the external Oracle table, and then treat the result as a local table?
If so, it sounds like it would be the equivalent of declaring the oracle table in MS Access in the table section, but with me still doing the security login programmaticall y, rather than having each user log in when they use the MDE - which is a requirement for my solution.

Is that correct? Or have I misunderstood?

One final question - I have been using ADODB in my VBA code. Can I mix and match with DAO? Or is there an ADODB equivalent to the CreateTableDefs ?


Thanks for your help.
Mar 26 '08 #3
FishVal
2,653 Recognized Expert Specialist
Hi,

If I understand you (and the quick look I've had at the help for CreateTableDefs ), are you saying that I can use that to create a link to the external Oracle table, and then treat the result as a local table?
If so, it sounds like it would be the equivalent of declaring the oracle table in MS Access in the table section, but with me still doing the security login programmaticall y, rather than having each user log in when they use the MDE - which is a requirement for my solution.

Is that correct? Or have I misunderstood?
You are already doing login programmaticall y opening ADO connection. Is this not the same?
Linking dynamically you may use connection string with password provided by user during login. Did you mean this?
On db close or on open before user logs (or in both cases) you should unlink the table. Sure that means one copy of front-end has not to be opened simultaneously by multiple users.

One final question - I have been using ADODB in my VBA code. Can I mix and match with DAO? Or is there an ADODB equivalent to the CreateTableDefs ?
Linking external table via creating TableDef object is exactly the same as linking using wizard. Does it work with the latter?
Mar 26 '08 #4
Zwoker
66 New Member
You are already doing login programmaticall y opening ADO connection. Is this not the same?
Yes, it probably is the same. I build the connection string using a usercode and password stored (encrypted) in a local table, and use that with some some constants and the correct ODBC DSN name for the database I want (there are several options). Just to be sure we are talking about the same thing, this is the code I use:

Expand|Select|Wrap|Line Numbers
  1. connStrForDB = "Provider=MSDASQL.1;Password=" & pPassword & ";Persist Security Info=False;User ID=" & pUsercode & ";Data Source=" & DSNname & ";DBA=R;"
  2. Set connForDB = New ADODB.Connection
  3. connForDB.ConnectionString = connStrForDB
  4. connForDB.CommandTimeout = 0
  5. connForDB.CursorLocation = adUseClient
  6. connForDB.Open
From then on I use the connForDB as a parameter when doing the reads of data from the Oracle tables - as you can see in my first post.

Linking dynamically you may use connection string with password provided by user during login. Did you mean this?
On db close or on open before user logs (or in both cases) you should unlink the table. Sure that means one copy of front-end has not to be opened simultaneously by multiple users.
There is no user log in - That is one of the requirements that stopped me using the reasonably simple external table declarations in MS Access, and switch to a connection string where I can control the login usercode/password. From the users perspective when they run the MDE they just see a form appear, choose whatever criteria they want from the pick-lists, and click the "Go" button. A little while longer (too long at the moment) the report appears in preview mode. If they are happy they click the Print button in Access and exit the MDE.

Linking external table via creating TableDef object is exactly the same as linking using wizard. Does it work with the latter?
Okay, I used to use the wizard linked tables when I thought that all users would have their own Oracle database logins, but no longer. But what you say is good news, as everything was much simpler when using the SQL over the linked tables. I was able to do joins etc... on all my data, treating it all as local tables whether they were or not.

There is an example of the CreateTableDefs in the help that shows an ODBC connected database being accessed. It looks a little confusing, but I'll try copying it and changing the connection string parameters, table names etc... to match mine, and see how it goes. I'm still unsure if I can include the DAO code in with my ADO? Or will I have to convert any of my ADO code to the DAO syntax?

Thanks.
Mar 26 '08 #5
ADezii
8,834 Recognized Expert Expert
Hi, Zwoker.



To the best of my knowledge it = True.



You may link external table dynamically via code just after a user has looged into the front-end (I hope you have a copy of front-end for each user session).

Refer to Access help concerning DAO.Database.Cr eateTableDef method and DAO.TableDefs collection (particularly Append method).
Exploring DAO.TableDef class will give you much useful information too.

Regards,
Fish
Hello FishVal, I'm not exactly sure if this is what you are referring to, so I'll just drop it in your lap. The code is as simple as you can get for Linking an External Table within Access, just call the Sub-Routine and pass it 2 Arguments. It works fine to Link an Access Table, but to adapt it to an External Oracle Table would need some adjustment on the Connect Property. If this is not what you were referring to, forget I dropped by (LOL).
Expand|Select|Wrap|Line Numbers
  1. Public Sub LinkTable(strTable As String, strSourceDB As String)
  2. 'This Function will DELETE any Table attachments and then Re-Attach them to
  3. 'completely insure the reliability of the attached Tables.
  4.    '  Parameters:
  5.    '    strTable - Name of the Table to be Linked
  6.    '    strSourceDB - Fully qualified Path and Filename of the Source DB
  7.  
  8. On Error Resume Next   'IGNORE ERRORS - necessary!
  9.  
  10. Dim ws As Workspace
  11. Dim db As Database
  12. Dim tdf As TableDef
  13.  
  14. Set ws = DBEngine.Workspaces(0)
  15. Set db = ws.Databases(0)
  16.  
  17. 'DELETE the Link if it already exists
  18.   db.TableDefs.Delete strTable
  19.  
  20. 'CREATE a new Link
  21.   Set tdf = db.CreateTableDef(strTable)
  22.  
  23. 'SET the Properties of the new Link and Append to TableDefs Collection
  24.   tdf.SourceTableName = strTable
  25.   tdf.Connect = ";DATABASE=" & strSourceDB
  26.   db.TableDefs.Append tdf
  27. End Sub
Mar 26 '08 #6
Zwoker
66 New Member
Hi ADezii,

Thanks for the code. It was me, not FishVal, that started all this. :)

On the assumption I can get the code to work with my external Oracle tables, does it mean that I could treat the result just as a local table, and use DoCmd.RunSQL to run my SQL code, without worrying about the ultimate source of the data? That would let me do what I wanted, which was have joins between two tables - One a "true" local MS Access table, and the other an external Oracle table.

Thanks.
Mar 27 '08 #7
ADezii
8,834 Recognized Expert Expert
Hi ADezii,

Thanks for the code. It was me, not FishVal, that started all this. :)

On the assumption I can get the code to work with my external Oracle tables, does it mean that I could treat the result just as a local table, and use DoCmd.RunSQL to run my SQL code, without worrying about the ultimate source of the data? That would let me do what I wanted, which was have joins between two tables - One a "true" local MS Access table, and the other an external Oracle table.

Thanks.
To the best of my knowledge, you are correct on your assumption in that once the Oracle Table is successfully Linked, it can be treated as though it was a Local Table with exceptions. A typical exception is that you cannot make Design Changes to the Oracle Table from within Access.

When I directed this to FishVal, I was referring to his Post #2 namely:
Refer to Access help concerning DAO.Database.Cr eateTableDef method and DAO.TableDefs collection (particularly Append method).
Exploring DAO.TableDef class will give you much useful information too.
Mar 27 '08 #8
Zwoker
66 New Member
Hi ADezii,

I spent a few minutes modifying your code to get it to connect to the Oracle database, then ran it to connect to a couple of tables. It appears to work fine. The real test will be using it to do the join that I want between the local and external tables and see if it works.

Thanks for all your (and FishVal's) help in this.

Once I have a confirmed working version I'll post my modified version of your block of code back here so that in the unlikely event that anyone else needs to do this odd combination of data activity, they can have a working example.


Regards,
Zwoker.
Mar 27 '08 #9
ADezii
8,834 Recognized Expert Expert
Hi ADezii,

I spent a few minutes modifying your code to get it to connect to the Oracle database, then ran it to connect to a couple of tables. It appears to work fine. The real test will be using it to do the join that I want between the local and external tables and see if it works.

Thanks for all your (and FishVal's) help in this.

Once I have a confirmed working version I'll post my modified version of your block of code back here so that in the unlikely event that anyone else needs to do this odd combination of data activity, they can have a working example.


Regards,
Zwoker.
Excellant idea Zwoker, kindly post your code for all to see and learn, I'm particularly interested in the String used for the Connect Property.
Mar 27 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
10224
by: Access Newbie | last post by:
I'm using Access 2000 and I'm trying to create a pass-through query to append all the data from a local table to a remote table. I'm using the SQL query editor in MS Access to create the query (I don't want to do this in VB code). I've set up the ODBC connection string in the query properties, which has been tested and works: ODBC;DSN=dev001 student99;Description=dev001...
4
2732
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want a variable with local scope, external linkage, and static storage. I believe I can do this for the file that does not define the variable by declaring it inside a function. Can I also avoid giving it file scope in the file that does define the...
5
8095
by: Steven C | last post by:
Hello! I am trying to connect to a SQL Server (MSDE) database in mixed mode authentication, via C#, but when I use the MSDE instance name, I keep getting an "Unrecognized Escape Sequence" error. The Data Source name has a backslash in it, and I'm guessing that this is causing the problem. How do I "Escape" the name, to make this work? I'm able to connnect in the .NET developement platform (Tools / Connect To Database), etc, using...
7
3633
by: Li Pang | last post by:
Hi, I'd like to know how to call a sub/function bu using a string containing its name, as an example as follow: Sub Main() Dim name As String = "TestMe()" ' need help here End Sub
2
1768
by: | last post by:
Greets, How does one connect to a local excel file using data wizard is it possible? I'm trying to connect to an excel file and populate a dataset and combo box with the data from excel TIA
12
1697
by: jimfortune | last post by:
I have a question based somewhat on: http://groups.google.com/group/comp.databases.ms-access/browse_frm/thread/ddde992b84f762bd/152bbc027bf00720?hl=en#152bbc027bf00720 A local table works well as a poor-man's repository for public variables with simple 'Types.' What are the relative merits of creating a class or collection versus using a local table? James A. Fortune
3
4264
by: asemeiks | last post by:
I'm using Access 97, Jet 4.0. the data resides on a Win 2000 domain server. Using .Net 1.1 and IIS 5.0 on a local XPPro computer I am trying connect to a Jet database on the server. If the data source is on the local computer I can connect ok. If it is is on the server I cannot connect and get the following error. 'Error message. "The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another...
2
1866
by: mvl_groups_user | last post by:
I am trying to look up data on about 1000 records from a 6 million record view on a DB2 database using msaccess. The 6 million record DB2 view is connected through a linked ODBC table (table A), and the 1000 primary key numbers I want are in a local msaccess table (table B). The most obvious solution is to join table A and B, but this is excruciatingly slow performance-wise.
1
1470
by: ragtopcaddy via AccessMonster.com | last post by:
I have a fairly static odbc connect string that should be visible in a text box on a form for reference purposes. It seems excessive to me to keep a table with 1 field and 1 record to record this string. Is it advisable to use a tag instead? I'm thinking of keeping the string in the textbox's tag, and providing a cmd button to change the value in the tag and updating the textbox value, on those rare occasions when it might be required. ...
0
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.