How to make a new OLEDB data connection in Excel 365 - excel

Looks like a silly question, but Excel 365 defaults to creating a new query type connection when you want to "get data". We are used to creating OLEDB connections to Oracle, SQL server and MS Access databases at work and in previous version of Excel, this was alwas a data connection. Excel 365, defaults to creating a new style Query (Data tab, Get data -> From Other Sources -> From OLEDB).
This new query style does not suit our needs. I haven't found any way to create the old style dataconnection in Excel 365. Can anyone give me pointers how to do this?
Background:
We are sending Excel files with data to customers and we change connection strings and queries using VB Script so as not to send out too much internal information (tables, connection details, credentials). So we update the dataconnection from a VBScript file program where we set connectionstring and sometimes the commandtext.
Differences I see:
In the Query, the connection string is something like "OLEDB:Provider=Microsoft.Mashup.Oledb.1;Data Source = $Workbook$;Location=CURRENT_PERIOD;Extended Properties=""
The commandtext is "select * from [Query1]"
Changing the commandtext here results in an error "[Expression.Error] The import consumables matches no exports. Did you miss a module reference?"
In the older connection style, de connection string is "OLEDB;Provider=MSDASQL.1;DSN=" with commandtext "select * from current_period". We could change the commandtext at will to get different results. We could also change the connection string to include login credentials so the query would run.
Also by changing the connection string you could change the connection to OLEDB connection, ODBC connection or a connection to an MS Access database. Changing the connection string in the new query type connection results in an error and does nog give a different type of connection.
It is just not working for what we do and I can't find a way to create the old style connection.

You need to enable the legacy import wizards.
Go to File > Options > Data. Then check all of the legacy import wizards.
Once these settings have been saved, you will see these options appear under the Data > Get Data menu.

Related

Excel VBA Using MS Access DB Should I close connection?

I'm creating an Excel VBA program for people at my office. The way I intend it to work is each person will have their own "portal", an Excel document where they can interact with the DB with their own user settings. This way there won't be issues with multiple people trying to use an Excel file at the same time.
The thing I'm not sure about is the Access Database I'm setting up. It's a single DB file that everyone can access. Currently the plan is to create the connection this way:
Dim accessFileLoc As String: accessFileLoc = "C:\Users\gmloo\OneDrive\Desktop\Grab Project\GrabDB.accdb"
'create the connection object, and open the connection
Set accessCon = CreateObject("ADODB.connection")
'i HOPE setting the mode like this will allow multiple users to connect to the same
'db at the same time
accessCon.Mode = 16 + 3 'adModeShareDenyNone + adModeShareReadWrite
accessCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & accessFileLoc
accessCon is a global Excel VBA variable that is currently designed to hold the connection as long as the Excel program is open. My question is, will this cause problems with other users all Querying the DB file at the same time? Should I be closing the connection for each user while it isnt needed, then re-establish it when they have to do a query? There's probably going to be up to 15 people using their Excel portal at any given time.
Thanks for your help.
You should be fine with multiple users connecting at the same time. However, due to memory and performance issues, I would recommend you close the connection after each query.

How can I read tables from Oracle DB in Excel and save the connection?

I am trying to create a Frontend for a database tool, in Excel because a) that's what is available to all prospective users in the company, and b) resulting data would otherwise be put into Excel anyway. We are doing this to sunset an existing Excel tool, that connected to a MS SQL Server, but had the logic built in VBA - hard to maintain, and the existing DB wont be available to us much longer. With the new system, all logic will be done server-side, and I only need to show the results.
I was able to do that with the MS SQL Server. But the new server is an Oracle DB, and the same tricks do not work there. (Btw, Oracle client 11.2 is installed on every machine.)
How can I do the following?
Connect to and read from Oracle DB from Excel
Have the DB-Connection saved in the Excel file
Password is saved within the Excel file (I know the counter-arguments, but in this case it's fine)
Use user-entered values as query parameters
What I already tried / What is not possible:
Power-Query lets me connect to Oracle, and allows for parameters. It is difficult for newcomers, and has more overhead for weak laptops, but it works. Unfortunately, Power-Query, by design, does not let you save the connection password.
ODBC-Connections for whatever reason do not seem to work with MS Query (Although the "Test connection" says OK). I need MS Query to utilize parameters.
OLEDB-connetions do work, but they do not offer parameters.
The only workaround I found to be working, is to utilize OLEDB connection to oracle, read the parameters from the user and change the query string via VBA each time to include them:
' Update table from oracle via OLEDBConnection
query = "SELECT *" & _
" FROM SAMPLETABLE sa " & _
" WHERE sa.KEY_1='$KEY2' " & _
" AND sa.KEY_2='$KEY2' " & _
" ORDER BY sa.ID" ' prepare the query
query = Replace(query, "$KEY1", key1) ' Replace placeholder with value for key_1
query = Replace(query, "$KEY2", key2) ' Replace placeholder with value for key_2
With Sheets("OracleLines").ListObjects(1).QueryTable.WorkbookConnection.OLEDBConnection
.CommandText = query ' Set the query text in the OLEDBConnection
.Refresh ' Refresh the connection
End With
I'd rather not go this route, as a) I was trying to eliminate VBA entirely, b) it adds another possible point of failure, c) the SQL query would be visible. (I do not expect malicious tinkering, but I'd like to be safe).

Read MS Access from Excel using Binary.Buffer to avoid errors accessing db in Admin mode

I have an Excel spreadsheet "Report.xlsx" which reads data from MS Access "Database.accdb". Within Report.xlsx, I wrote a simple macro "Macro1" which refreshes the data table in the spreadsheet.
Within MS Access, I am connecting to Excel and launching the macro.
This process fails with the following error in Excel:
DataFormat.Error: The database has been placed in a state by user 'Admin' on machine 'BRNMBL0324' that prevents it from being opened or locked.
Details:
Portal front-end extracts.accdb
Here is the MQuery that fails:
let
Source = Access.Database(File.Contents("Database.accdb"), [CreateNavigationProperties=true]),
#"Table 1" = Source{[Schema="",Item="My database table"]}[Data]
in
#"Table 1"
If I read the database using a Binary.Buffer (per https://social.technet.microsoft.com/Forums/en-US/67852ccf-3c04-42c7-ac5c-6213d4d7b3a2/the-database-has-been-placed-in-a-state-by-user-8216admin8217-on-machine8230-that-prevents?forum=powerquery), the process works:
let
MyDbBinary = Binary.Buffer(File.Contents("Database.accdb")),
Source = Access.Database(MyDbBinary, [CreateNavigationProperties=true]),
#"Table 1" = Source{[Schema="",Item="My database table"]}[Data]
in
#"Table 1"
Since there is only one query in the spreadsheet, I am confident that the issue is not concurrent queries. I closed and reopened the Access db, so I know that the issue is not an unsaved object in MS Access.
Is using Binary.Buffer a robust way of addressing this issue?

Selecting a schema to connect to when connecting over an ODBC connection in Excel's Power Query

So I have a fairly simple query (proof of concept) where I'm able to dynamically pull in data from a database depending on my Excel sheet inputs. For example:
let
Source = Odbc.Query("dsn=Dev 2", "select * #(lf)from job_id JI#(lf)where JI.job_ID = " & Text.From(GetNamedRange("SQLJobInstanceID")) & "#(lf)")
in
Source
Hurray, it works! However, when I was setting up the connection, I needed to log in. Part of the login includes the schema that I wanted to connect to. Username[Schema] is how it's done. Now that I've connected, I'd like to select a different schema to connect to - but I'm not sure how I can either modify the schema, or log out and log back in.
(Also curious if the connection is storing my credentials, which would be problematic, or if other people would need to log in with their credentials)
I believe I can also edit which ODBC connection I'm using by editing the "dsn=Dev 2" portion of the code (Again, will probably turn it into a named range drop down menu.... the challenge becomes dynamically figuring out what ODBC options each user has and pulling those through...)
Thank you

Unable to select from SQL Database tables using node-ibm_db

I created a new table in the Bluemix SQL Database service by uploading a csv (baseball.csv) and took the default table name of "baseball".
I created a simple app in Node.js which is just trying to select data from the table with select * from baseball, but I keep getting the following error:
[IBM][CLI Driver][DB2/NT] SQL0204N "USERxxxx.BASEBALL" in an undefined name
Why can't it find my database table?
This issue seems independent of bluemix, rather it is usage error.
This error is possibly caused by following:
The object identified by name is not defined in the database.
User response
Ensure that the object name (including any required qualifiers) is correctly specified in the SQL statement and it exists.
try running "list tables" from command prompt to check if your table spelling is correct or not.
http://www-01.ibm.com/support/knowledgecenter/SSEPGG_9.7.0/com.ibm.db2.luw.messages.sql.doc/doc/msql00204n.html?cp=SSEPGG_9.7.0%2F2-6-27-0-130
I created the table from SQL Database web UI in bluemix and took the default name of baseball. It looks like this creates a case-sensitive table name.
Unfortunately for me, the sql_db libary (and all db2 clients I believe) auto-capitalizes the SQL query into "SELECT * FROM BASEBALL"
The solution was to either
A. Explicitly name my table BASEBALL in the web UI; or
B. Modify my sql query by quoting the table name:
select * from "baseball"
More info at http://www.ibm.com/developerworks/data/library/techarticle/0203adamache/0203adamache.html#N10121

Resources