[SOLVED] Issue Once Setup as SaaS |
10/4/2024 10:12:02 AM |
ASPRunner.NET Tips and tricks | |
G
Garyl author
First I have setup my application as a SaaS Solution, which works well following these steps. https://xlinesoft.com/blog/2019/10/03/saas-application-design/ There was an issue reported in PHPrunner https://asprunner.com/forums/topic/29872-Table-not-found That represents the exact same issue I am running into in ASPRunner Enterprise/Postgres back end for the DB, I do not see any resolution to it. This was working once, when I did not have the app setup with SaaS authentication. User information is held in saasdb In my test database in this environement I have a table called tasks, which I have been able to add a new record and update just fine. I decided to capture some information and when saved I added some code to insert into a table called tasktimetracking, in the test database. The code was placed in After Record Updated dynamic data = XVar.Array(); Now the task record I am editing in test database does not save, the insert to the other table as outlined above does not occur and I get this error. Error received. Technical information Clearly this table does exist, and I can run queries and inserts just fine on it manually. If I remove that code and edit the same task record it saves without and issue, as soon as I add the code back it, it throws the error, and again the current record I am editing does not save, nor does the insert occur in the other table. So after of week of messing around with this trying to fgure out what is going on I decided this morning to prove a theory. In the saasdb, which only has the users which are mapped to what DB they have access to. I went ahead and added public.tasktimetracking table to that DB. Now when I perform an edit, it updates the record in test and inserts the other record in the saasdb. This tells me that in After Record Updated it does not know which database the current user is accessing and defautls back to the saasdb. I must be missng something. Gary |
|
G
|
Garyl author 10/7/2024 |
And just realized I put this in the wrong category, I don't see a way to change that. |
G
|
Garyl author 10/12/2024 |
I have resolved this issue, and while this was challenging, I want to document how. I have seen this question ask several times with no answer. This was a lot of guesswork on my part. Initially, I had the app set up stand-alone, using one database. When I updated a record, I had a process to update another table in the “After record updated” event. dynamic data = XVar.Array(); Worked extremely well. I then decided to set the app up for SaaS. So, starting from scratch, I followed the instructions here. https://xlinesoft.com/blog/2019/10/03/saas-application-design/ This would work well, and in testing, once the user logged in, they were directed to the correct database. On the front end, they could add, edit, and delete a record without issues in the correctly assigned database. I called the database used for authentication saasdb ; as in the instructions. You can name it whatever you want. The database for the data I called master. I cloned the master to multiple databases that would represent each client. In the Before Connect, I have this. (FYI I am using PostgreSQL) After Login, I have this: In the user table, I added a column called Database and set the user to what database they should have access to. This way, when they log in, they are connected to the correct DB. As I said, this all worked well; however, the “After record updated” broke. You would think that since the app on the front end knows which database the users are working with, the event would also. I was trying to write to another table in the same database after the update, and it could not find it. Fighting with this for about a week, I created the same table in the saasdb database (used for authentication). When the event was fired, it was written to that table, defaulting to the authentication database instead of the assigned one. I then found in the documentation the DB.SetConnection command, while I was still just trying to write to the associated database the user was assigned to , I presume the event had no clue which DB at that point. So, I put the session variable for the assigned DB in the “DB.SetConnection”, and was able to prove it was setting it correctly; in this case, the user was assigned the test database. However, it still could not find the table in the database and wanted to write to the saasdb. After several days of throwing up my hands, I reread all the instructions. And decided to hardcode the DB.SetConnection to “master” Which did not work, at first. Going to the tables in ASPRunner, I noticed that when I added the tables (saasdb and master, it appended “at local” to the end of them. saasdb at local I renamed them back to saasdb and master, compiled the app, and logged in with the test user to the test database, and made sure existing functionality was still working. I updated the record, and the “After record updated” event was fired and wrote to the table in the test database. So there were two issues. The database listed in the tables section of ASPRunner were incorrectly named And the DB.SetConnection must be the Database you are using as the master in ASPRunner. Then it magically changes it to the one assigned. Like I said, be it right or wrong, this is working seamlessly for me now. I do feel the events should look at the session variable for the assigned database, and only if you write to another database should you have to set it using DB.SetConnection. |