I'm playing around with a table in an MS Access database. The table has a primary key of CLIENT_NUMBER. My corporation maintains an Oracle database that has a table which contains clients contact information (address, phone numbers, emails, etc). It also has the CLIENT_NUMBER field. I got to thinking that maybe I can join the 2 tables from the different databases and run some queries. I dug around on the net and I couldn't really find any reference, so I think this is a long shot and a silly question, but is that possible? Maybe through a DB link or something? For reference, I use SQL Developer 3.2.xx for sql developing.
I would copy the table in oracle to Access using what's called a sqlpassthrough query in Access. linked tables to oracle in my experience, perform very poorly, and if you are also thinking about joining to a local table in Access, probably much worse.
Passthrough queries are very quick since Access simply just sends the query for execution to the target server/database based on the connection you identify for the passthrough query, hence the name "pass-through".
The driver in the connect string may not work for you, and it may need more info depending on how things are setup in your environment, so you will have to work that out.
'creates the passthrough query to oracle
With CurrentDb.CreateQueryDef("qOracleConn")
.Connect = "ODBC;Driver={Microsoft ODBC for Oracle};Server=oracleservername;Uid=oracledbusername;Pwd=oracledbpassword;"
.sql = "SELECT * FROM tableinoracle"
End With
'creates the local table in access
CurrentDb.Execute "SELECT * INTO OracleClients FROM qOracleConn"
Related
I'm using pyodbc to connect to a machine database, and query a number of tables in that database using
pandas.read_sql(tbl,cnxn), where tbl = "SELECT * FROM TABLE", cnxn is pyodbc.connect('DSN=DATASOURCE;UID=USERID;PWD=PASSWORD').
It works on most tables, but some tables return:
DatabaseError: Execution failed on sql 'SELECT * FROM TABLE': ('42S02', '[42S02] [Microsoft][ODBC driver for Oracle][Oracle]ORA-00942: table or view does not exist (942) (SQLExecDirectW)')
These tables that return an error, when opened in MS Access, have multiple columns with a key icon on the left when opened in design view (thus a compound primary key, made up from multiple columns).
Is this is the reason I'm having the error described above? How can I solve this?
Edit: as shown in this screenshot, there are multiple columns marked as making up the primary key in design view:
Edit2:Thanks for the feedbacks. After checking ODBC Data Source Administrator window, this data source is on 32-bit platform, and its driver is Microsoft ODBC for Oracle.
I don't think table's name is the issue, because other tables worked and they have the same naming convention (table name is in this format NAME_OF_THE_TABLE). Trying to avoid showing the table name because working on a company project.
I did research the concept of primary key and realized that there can only be one for a table, but as shown in the screenshot attached, there are a five fields shows a key icon on the left.
Before anything, understand MS Access is a unique, GUI tool that maintains its own default database, JET/ACE Engine, but can connect to other databases as well including Oracle, SQL Server, Postgres, etc. via OLEDB/ODBC connections. Essentially, both MS Access and Python are doing the same thing: make an ODBC connection to Oracle (the actual backend database).
Because all linked tables connect fine in MS Access, try matching connections and queries in Python. Likely, the issue involves table names, schema connection, or user access.
Table Name: Your table contains misspellings or reserved words, or a mix of upper or lower cases as defined in their CREATE TABLE setup causing case sensitivity, so Table as defined with CREATE TABLE "Table" is not the same as TABLE. For this reason, use the exact name in the MS Access linked table and wrap with double quotes.
pandas.read_sql('SELECT * FROM "Table"', cnxn)
(Do note: double quotes in SQL is entirely different meaning than double quotes in Python and are not interchangeable with single quotes.)
Connected Schema/User: Incorrect schema. Because schemas in Oracle are more or less users, you may have multiple connections for your MS Access linked tables. Though they all point to same database server with same ODBC driver, the user differs each with different underlying tables. To resolve, match the Python ODBC connection with the MS Access ODBC connection:
You can locate the MS Access connection string under: Table Design (from Navigation Pane) > Property Sheet (from Ribbon) > Description. Use this in the pyodbc.connect(...) call. Likely only the uid and pwd would differ if working across schemas.
Unprivileged User: The connected user does not have select privilege on that table.
I am very new to SQL, MS Access & PostgreSQL. So this might be a very silly question but somehow I can't figure it out. I'm trying to run SQL queries in access and my data is in a PostgreSQL database table which was linked to access by my colleague earlier. When I make this simple query why do I get an error that the table doesn't exist? Is the syntax different for linked database tables? Or is the link not yet established?
You have created a Pass-Through query. This query is executed on the server, not in Access, so you need to use the original table names from the PostgreSQL database.
So it's not FROM public_tb_change but FROM tb_change.
Or maybe FROM public.tb_change, if public isn't the default schema.
I advise to rename your linked tables to the original name (remove public_), that makes things much less confusing. The schema name is automatically added by Access when linking the tables.
I am new to access. I am using a tool/access database someone built, and it has an ODBC connection to an Oracle SQL database in it.
There are different queries on the side panel, and some of them are delete queries.
If I run these delete queries will they just modify data in my local access database without modifying the data in the Oracle Database?
Yes these will change something in the database whether its linked with another access database table or oracle table and within the database. To review the query you can open the queries in design view and run a normal select query so you can see what the queries are deleting. You can have a normal table image and or globe with a arrow in front pointing towards the table then its linked. A lot of times when I am testing I just run select queries and then I make a copy of what I will be deleting just in case anything goes wrong.
Ok so I have a little problem...
In my project we have a Oracle SQL Server. In the database I have access to some of an other users tables:
Tables:
|-bla
|-bla
Users:
|-otherUser (let's just call him that)
|-Tables:
|-aTable
In Oracle, to access the aTable table I use SELECT * FROM otherUser.aTable
Now, we also have a MS SQL CE database to which I sync the data from the OracleDB using the MS Sync f/w. And in the CE db - after sync - I get a table otherUser.aTable. This sounds good, so even though the CE doesn't have the User concept it just adds the same table.
BUT the problem is that when calling the same SQL query on CE as on Oracle I get a The table name is not valid error. Instead if I want to get the content of the table, the two ways that I have found to work is surrounding the otherUser.aTable with either [] or "".
However neither of them seem to work with Oracle. The [] seem to be an illegal name, and the "" seem to search for a table called just that (not an other user).
So why don't I just use the one way on Oracle and the other on CE? well I also use NHibernate as a ORM and it kind of needs the same table name for both the databases...
Is there a third way to encapsulate the table name that works with users in Oracle and just works in CE? or do you have any other ways to fix this issue?
I have no experience with MS SQL, but it seems like a problem that might be solved with synonyms on Oracle side.
Try to create synonym "otherUser.aTable" for otherUser.aTable in Oracle.
I've got about 13,000 AccountIDs that I need to pull various data from several data tables using left-joins. The total # of accountIDs is in the millions. I don't have write-access to the server but I was wondering if there was a way I could maybe create a custom/temporary table anyway and do a join to that rather than writing a really, really long Where AccountID in (.....) statement. The accountIDs are currently in a single Excel column so I'd have to get them back in the server somehow.
Thoughts?
You can use OPENDATASOURCE to access your Excel file, but someone will have to push you the Excel file to the server (not ideal).
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\DataFolder\Documents\TestExcel.xls;Extended Properties=EXCEL 5.0')...[Sheet1$] ;
You can ask your DBA team to install a SQl Server Client on your local machine and set up a linked server to the live server, and you are all set. Ask them to set up a view of the data you need, and give you access to the view. That's all you need, I guess.