cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dewriffic16
New Member

Is there a way to change SQL database from within a App?

I have an app that is connected to an Azure SQL server and the sandbox database that has about 25 different tables.  I have a production database on that same server with identical table names/structure.  I would like the user to be able to switch between the production database and sandbox database using a toggle and have the whole app switch the database being referenced from production to sandbox database.  I don't mind if I need to reload the app or refresh etc, just want to avoid having two identical apps with the only difference being the database name.  Is there some way to parametrize the datasource / database name? 

I know I could probably do a save as and connect a 2nd app to my production database, but I'd like to only have to maintain 1 app.  I've also worked with unpacking the .msapp file and I see that there is a connections.JSON file that I could simply change one line on to reference my new database, but again, no way of me editing this file on the fly I'm guessing from within the app. 

Any and all suggestions welcomed... Thanks in advance, 

-David
@Shanescows 

1 ACCEPTED SOLUTION

Accepted Solutions

As I said earlier, once you have connected the Databases, be referring to the tables not the Databases.

 

So if you are connecting to a Gallery and you have a Toggle button, on the items property use;

 

If( Toggle1.Value,Table1, Table2)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

View solution in original post

4 REPLIES 4
eka24
Super User III
Super User III

My understanding of your situation is to switch between tables in two databases not really switching between databases.

What your App use are the tables no matter where they are connecting from.

 

So I suggest you connect both databases to the App, select the appropriate tables from each of them.

 

Finally use the toggle to switch between the tables example;

If (Toggle1.Value,Table1,Table2)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

Thanks for the response Eka, I do have two separate databases, both with identical table names with the hope being that I can simply switch the datasource from one to the other without having to change the whole app to reference alternate tables.  As it's setup now database1.Table1 would be similar to database2.Table1 so in my items formulas all they reference is Table1 but I need someway to change the direct reference to database 1 or 2.  Hope that makes more sense. 

As I said earlier, once you have connected the Databases, be referring to the tables not the Databases.

 

So if you are connecting to a Gallery and you have a Toggle button, on the items property use;

 

If( Toggle1.Value,Table1, Table2)

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

View solution in original post

Thanks again, I think this is the solution I'm trying to avoid since I would have to import the exact same tables from my second database, the tables would then be duplicates and it auto inserts a _1 after each table.  For instance I would then have a Table1 and a Table1_1 after importing the second database since they are exact duplicates.  I would then need to go through the hundreds of places where I reference each data table and write conditionals to reference one table or the other based on the toggle.  

Basically when I connect to the SQL datasource I can easily select my server and database, but I can only do this in the power app studio, I want to be able to edit these connection settings at runtime or on app start to avoid having to duplicate all my tables... 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (36,289)