Why am I getting "OLE DB or ODBC Error" when importing data from Azure SQL into Power BI Deskop, using parameters for db details? - powerbi-desktop

I need to connect Power BI to an Azure SQL database. If I enter the server name and database directly into the "SQL Server database" dialog, it connects, prompts me for credentials, allows me to select tables, and subsequently imports data just fine. screenshot of database details dialog
However, if I enter the server and database name as parameters (screenshot of adding database details as parameters), and use the exact same server and db names as the "current value" of the parameters, I get the same table selection options, and can see data previews, as before, but when Power BI tries to import the data, I get the following error:
"Failed to save modifications to the server. Error returned: 'OLE DB or ODBC error: [Expression.Error] The import serverName matches no exports. Did you miss a module reference?" for every table I try to import. serverName there is the name I gave to the server parameter.
error dialog
Can anyone help?

Related

Using Oracle.Database M language function in Power BI Desktop

I am writing a custom connector for Power BI Desktop. The custom connector would simply connect to Oracle DB and fetch some data.
For this, I am trying to use Oracle.Database data source function which is defined as below:
Oracle.Database(server as text, optional options as nullable record) as table
Clearly there is no option to pass the DB credentials in the above function.
Questions:
Do we not need to pass DB credentials to this function?
From where this function pick the DB credentials?
Would it be picking up the credentials from Extension.CurrentCredential() function?
Secondly, I have enabled "UsernamePassword" kind of authentication in my connector so when I try to use the connector, it prompts me to supply the username and password. After typing in the username and password, when I click "Connect" button then it simply shows the message "Please specify how to connect". Any ideas why it is showing this message when I have just provided the credentials on the dialog box?

connection to SQL database with Office script

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.

Using Excel as the front end, Azure as the backend

I have a SQL Database on Azure to which I can successfully get connected from within an Excel file. I am using ADO and the connection string uses my own username and password. Since this file will be used by many users, how can I create a generic login and password so that I would not give out my own username and password in the code? The Excel file runs many VBA macros to communicate with the Azure SQL database.
I am using Excel 2010 (yeah, it is old, I have to) and this is my connection string:
mstrConnectionString = "Driver={SQL Server Native Client 11.0};" & _
"Server=tcp:<servername>.database.windows.net,1433;" & _
"Database=<databasename>;" & _
"Uid=<myusername>#<servername>;" & _
"Pwd={MyPassword};" & _
"Encrypt=yes;Connection Timeout=30;"
According your comment, I have an idea that you can create a new login/user for you Azure SQL database.
Then you use this user and password as public account to get or writer data from your Azure SQL database within Excel.
Here's the example T-SQL statement, this code is create a new login and a user in your Azure SQL database. You can run this query in SSMS:
--running in master db
USE [master]
GO
CREATE LOGIN [sagarreadonly] WITH PASSWORD='password'
GO
-- running in Azure SQL DB
USE [DataEncryptDemo]
GO
CREATE USER [sagarreadonly] FOR LOGIN [sagarreadonly] WITH DEFAULT_SCHEMA = Marketing;
GO
EXEC sp_addrolemember 'db_owner', 'sagarreadonly';
GO
The new user is created as 'db_owner' to the specified database.
For more details about database roles, please see Database-Level Roles.
About login and user:
A login is used for user authentication
A database user account is used for database access and permissions
validation.
Logins are associated to users by the security identifier (SID). A login is required for access to the SQL Server server. The process of verifying that a particular login is valid is called "authentication". This login must be associated to a SQL Server database user. You use the user account to control activities performed in the database. If no user account exists in a database for a specific login, the user that is using that login cannot access the database even though the user may be able to connect to SQL Server.
A Login is an identity used to connect to a SQL Server instance. A User allows you to log into a SQL Server database and is mapped to a Login. So you will need to first create a Login, before you can create a User in SQL Server.
Hope this helps.
You can create a "Database login" dialog box to prompt a user for database connection information by using text boxes, buttons, or other dialog box controls. Typically, when you type text in a text box, the text appears as you type. However, you can use a property of the Microsoft Visual Basic for Applications (VBA) Edition User Form to create the effect of a hidden or "masked" text box for creating a password dialog box, where you do not want the text that is typed in a text box to be "visible". Here you will find how to do that.
The information the user types on the "Database login" can be used to build the connection string you posted above.
To create a custom dialog in Excel please follow this instructions.

After migrating database and mobile service the mobile service is still using old schema

I needed to move an azure project to a new account. My azure project consists of a SQL database and a mobile service connected to that database.
I moved the database by backing up the database into a .bacpac file and importing it in a new Azure account. I recreated the mobile service manually. Because the mobile service needed a different name, I changed the schema on the imported tables by running:
ALTER SCHEMA [NewSchema]
TRANSFER [OldSchema].[TableName]
Now after migration the SELECT works. In the azure portal I can see all the tables have rows, and the mobile service can read from the database. The problem however is in insert, and in Custom API's of the service.
Those seem to still work with the old schema in mind:
Insert: Error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name '[OldSchema].[TableName]'. (SqlState: 42S02, Code: 208)
CustomAPI: Error: [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid object name '[OldSchema].[TableName]'.
There are no references to the old schema that I can find anywhere. Not in the codebase, not in the database.
I even went and executed
SELECT * FROM sys.database_principals
alter user <userName> WITH DEFAULT_SCHEMA = [NewSchema]
for all users.
I am out of ideas. What am I missing, where is it referencing the old schema?
Thank you for your help!
EDIT: I have just tried printing SELECT SCHEMA_NAME() within the Custom API I am trying to execute. It printed the correct, new, schema name. When I printed SELECT CURRENT_USER the correct user is printed, with the correct default schema. I am now more confused than ever.
Can you check your database triggers? There's a trigger that runs on Insert/Update/Delete that may still have a reference to your old schema.

How can a SharePoint SQL connection be set to query by the current login name?

I have a SQL table that needs to be queried by the login name. So, using SharePoint designer I successfully created a database connection, but I can't use the properties exposed by Profile nor Session as input parameters because they are not supported (A dialog pops up with a message indicating this)
How else can I query a SQL datasource by using the current login?
-Edit
To create the data connection, proceed as follows
Open the data source library
Expand database connections and click on connect to a database
Enter the database settings
Select "specify custom Select, Update, Insert, and Delete"
Click on Edit Command
Add a parameter and select Profile and enter UserName as the property name
An error will follow stating that this is not supported.
Unfortunately, you don't give many details but I think you're looking for the LOGON_USER Server Variable: Data View / Data Form: Parameters You Don’t Know About.

Resources