Forum Discussion
Query on Dynamically Entering Database Credentials in Power BI
Hi,
I would like to inquire about a method for dynamically entering database credentials (SQL Server name, username, password, and port) in Power BI. Specifically, I want these credentials to be stored in an Excel file, and for Power BI to fetch them dynamically during each data refresh.
Please advise on how this can be accomplished?
- Anonymous1 year ago
Hi All,
Firstly lbendlin thank you for your solution!
And mujibjee , You are trying to implement a query for dynamic input of data credentials, right?
Here's a solution we've found for you, and we hope you find it helpful:
1.Store Credentials in an External File (Excel or Config File):
Create an Excel file or any external configuration file to store the database credentials (e.g., server name, username, password, port).
Format the file as a table with appropriate headers, such as Server, Username, Password, and Port.
2.Use M Code (Power Query) to Fetch and Apply Credentials:
Open the Advanced Editor in Power Query and reference the imported credentials dynamically.
Example:let Source = Excel.Workbook(File.Contents("PathToYourExcelFile.xlsx"), null, true), ConfigTable = Source{[Name="YourTableName"]}[Content], Credentials = Table.ToRecords(ConfigTable), ServerName = Credentials{0}[Server], Username = Credentials{0}[Username], Password = Credentials{0}[Password], Port = Credentials{0}[Port], ConnectionString = "Server=" & ServerName & ";Port=" & Port in ConnectionString3.Dynamic Connection Setup:
Replace hardcoded database connection details with the variables (ServerName, Username, Password, Port) in the connection settings for your data source.
4.Refresh Configuration during Updates:
Power BI will fetch the updated credentials from the external file during every data refresh.Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
Hi All,
Firstly lbendlin thank you for your solution!
And mujibjee , You are trying to implement a query for dynamic input of data credentials, right?
Here's a solution we've found for you, and we hope you find it helpful:
1.Store Credentials in an External File (Excel or Config File):
Create an Excel file or any external configuration file to store the database credentials (e.g., server name, username, password, port).
Format the file as a table with appropriate headers, such as Server, Username, Password, and Port.
2.Use M Code (Power Query) to Fetch and Apply Credentials:
Open the Advanced Editor in Power Query and reference the imported credentials dynamically.
Example:let Source = Excel.Workbook(File.Contents("PathToYourExcelFile.xlsx"), null, true), ConfigTable = Source{[Name="YourTableName"]}[Content], Credentials = Table.ToRecords(ConfigTable), ServerName = Credentials{0}[Server], Username = Credentials{0}[Username], Password = Credentials{0}[Password], Port = Credentials{0}[Port], ConnectionString = "Server=" & ServerName & ";Port=" & Port in ConnectionString3.Dynamic Connection Setup:
Replace hardcoded database connection details with the variables (ServerName, Username, Password, Port) in the connection settings for your data source.
4.Refresh Configuration during Updates:
Power BI will fetch the updated credentials from the external file during every data refresh.Hope it helps!
Best regards,
Community Support Team_ Tom ShenIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.