connection to SQL database with Office script - excel

is it possible to make a connection between Office 365 to SQL database using Office scripts? something simillar to ADODB.Connection in Excel VBA

You can't connect directly to a database using Office Scripts. You can still get data from a database but the process would need to be a bit different:
Instead of querying a database directly, the data would need to be returned to some API (e.g. as JSON)
Instead of providing a username / password to connect to the database, you'd use an API key.
Once you had access to an API and provided an API key, you could use fetch to get the JSON and work with the data in Office Scripts.
You can read more about using fetch with Office Scripts here
In addition to this type of process, you could also trying using something like PowerAutomate to query the database directly.

Related

3-Legged OAuth2 Authorization code flow for Excel?

This might be a long shot, but I'm using the MYOB Business API which has the same OAuth authorization flow as the LinkedIn API - 3-legged - and am planning on making queries to it through Excel, most likely power query.
The big issue with this is obviously dealing with the sending and receiving of the code=, access_token and refresh_token. Most of the searches I've done relating to using Power Query and OAuth seem to only deal with username and password OAuth and not the authorization flow, shown here https://developer.indeed.com/docs/authorization/3-legged-oauth.
I'm curious if there is Power Query M Language code out there that I haven't come across or if I have to go the route of building an OData Feed (or another method?) on top of the API so that it can be queried in Excel?
Any help or further direction would be appreciated.
I should also note they have a website containing their Postman collection using different languages here; https://accountrightapi.myob.cloud/?version=latest#f2b93dfa-803f-44b9-8a07-756874494227
The short answer for Excel is: No, but Asterisk.
Excel Power Query doesn't support custom connectors (as of 2022-02-07)
To securely use Auth2 flow, it requires a custom connector
There is some built in support, if the connector supports it. ( Like Web or OData)
Here's a summarized version of Chris Web. (He's a Power Query Wizard) Connecting To REST APIs With OAuth2 Authentication In Power Query/Power BI # blog.crossjoin.co.uk
the definitive, Microsoft-endorsed answer to this question is:
If want to connect from Power BI to a REST API that uses OAuth2 authentication then you need to build a custom connector.
You can use OAuth2 credential flow in regular Power Query queries without needing a custom connector.
this is not recommended: it’s not secure and it’s not reliable. In particular, hard-coding usernames/passwords or client ids/client secrets in your M code is a really bad idea
The only exception is that you can connect to some APIs that use AAD authentication using the built-in web or OData connectors
To use a custom connector in the Power BI Service, it requires an on-premises gateway
How to implement OAuth2 flow
Creating a Custom Connector
Using built-in OAuth2 flow using with Azure Active Directory using the Web and OData connectors
I used excel VBA code to handle the MYOB API connection by invoking MS Edge, with Seliumn Basic drivers.
VBA then executes the MYOB API Connector Add-On.
VBA receives the database files I require from MYOB and writes them to a.txt file location on my PC.
VBA then refreshes the data connections for Power Query which runs the M Code I’ve written in advanced editor.
When I close excel, VBA closes all the connections and MYOB add on connector.

Passing data from office JS storage to Queries and Connections

I have an Auth flow in my add-in that returns API token which I want later to use in my Queries and Connections (Power BI/Power Query). How can I safely transfer/read the token from Office JS storage to be usable on Power Query Editor?
Right now I created a custom excel function (formula) that returns this token, but those functions can be used only in Cells. There are two problems with that:
The API token will be stored in a cell and thus preserved together with the spreadsheet which is not OK
The power query might not expect the cell to be updated asynchronously as the JS functions are

How to query an access database on SharePoint Online

I would like to ask you, if there is any way where I can query an Access Database, which is stored on SharePoint, using Excel Vba code and without using the "Get Data" functionality in the Excel.
In other words, how I can connect my excel spreadsheet to the access database on SharePoint Online using ADODB or DAO etc.
Thank you in advance.

Office 365 and Sharepoint apps

is there a way to create a access web app and use as database an azure sql database. and use it as the main application database or a secondary one.
Either is it possible to create a database that is shared over more than one sharepoint app.
Last but not least is there a way to catch the visitors microsoft mail and use it in a macro to change the views depending on the accesslevel we want him to have on our app.So we can create for example user based profile, either with that way or with creating a user login and registration form.
Thanks in advance.
is there a way to create a access web app and use as database an azure sql database
When you design and modify in Access 2013 or later, the data and database objects are stored in SQL Server or Microsoft Azure SQL Database, so you can share the data within your organization using on-premises SharePoint 2013 or Office 365 for business.
Last but not least is there a way to catch the visitors microsoft mail
You could use the Access Custom Web App Function to get the email address , it could be used in user interface (UI) macros .
UserEmailAddress Function (Access custom web app)

How can I make MS Query (in Excel) see tables with field-level security on SQL Server 2005 or later?

MS Query, when connecting to SQL Server through an ODBC Data Source, uses the system procedure "sp_tables" to retrieve a listing of tables in the database. The source for sp_tables can be viewed but not altered. The problem with this procedure is that it will not return a table name for which the connected user has permissions to access only certain columns. It only returns tables for which the connected user has full SELECT access.
We are using database roles with explicitly granted access to tables in our data warehouse. We have a model for building security down to the field level, but cannot enable it due to the problem above. Most users are accessing through MS Query and Excel, because everyone has MS Office and we have trained them in its use.
Since many reports have already been built around this product, migrating users to another product is not an option at this time.
One suggestion has been to create views with only the available columns and grant select on those views. This would work, but 1) would defeat the purpose of field-level access and isn't too far off of our current "work-around" and 2) would require retraining the users on using the new views instead of the tables they are used to.

Resources