Codeigniter - Connecting to multiple database that are on different server - database

I want to implement a functionality where I want to change the database based on the user selected company.
For example:
When User A visit my site he needs to login, after the login he can search his company, until this point I am connecting the user to my server db; after he search his company and press the done button I have to make a connection to his server and dynamically change my server db to his company server db. (the reason of doing this is my web app is gonna used by multiple companies so companies gonna have different employee records so i have to connect to db of their server to get their employers records).
I am really confused how to achieve this what data I need to store in my db for making connection to different server db?
As far I researched I understood that I need to store the dbname,dbusername,dbPassword.
Do i need to store anything else? Do I need to store the host name too? Can any of you guide me how to achieve this?

Are you creating individual database as per the company name of that employee, or are you using same database for all the employees?
If you are creating individual database for individual users, you store the company name in to your users information table and when ever you are login, you fetch the company name of that user and store it in to session
and while fetching the record you use the stored company name in to the session for connecting to the database as :
suppose you want to fetch the record from companymaster or some other table you can use like as :
$companyName=$this->session->userdata('companyName');//stored company name in to the session
Now, use the table as
$this->db->from("$companyName"."Your Table Name");
Thanks.

Related

PowerApps - Save data entries to empty data table, and save in SQL Server

I have made the following screen in Power Apps:
My goal is simple: I wish the end-user to enter data into these text boxes -> User clicks "OK" button -> Data is saved for the user right below in a relational data table with columns; Name, Amount, and Measure.
Once all data entries are made, a "Save" button should send the complete data table in JSON format as input for a SQL Server stored procedure, which accepts the parameter #json. How is this accomplished?
What I tried: Tried making a gallery, data table, form, etc. But all of these require me to connect to an existing data set. I instead want the user to create the data set, and then have the data sent to a SQL Server database.
Use the built-in SQL Connector
Create the table in the SQL database
Add the SQL Connector to your PowerApp
Authenticate to the connector
Select the table to connect to
Then write your Patch() logic accordingly
You don't need a Stored Procedure
As an alternative, if you realllly want to use a Stored Procedure, connect Power Automate to your PowerApp and run the Stored Procedure from there. This introduces dependencies though. Your call. Example
Beware:
If you don't setup the SQL Server with Active Directory Auth, you will share your permissions, implicitly, with whomever you share the PowerApp with.
Best to use SQL to create a Group, Assign Role(s) to the Group, then assign Users to the Group
Then each user of the PowerApp will have to explicitly authenticate using their perms
See here

ASP.NET MVC display users recent searches and additions to SQL Server database

I am creating an ASP.NET MVC site that can be accessed by an Active Directory group. The basic functionality of the site is:
User can navigate to many different pages which display data from different tables in the SQL Server
User can search by any column in each table on the site to display corresponding records
User can create/delete/edit previously stored records from the connected SQL Server tables
I want to create a main page for the site that is personalized for each user in Active Directory. I was hoping to display previous changes to the database (i.e records added or edited) as well as the user's previous search history so that they can click on a link and it takes them to a results table that they have accessed before.
I have looked into logging the user's activity, but so far all I can find information on is logging errors/bugs that different users experience on the site. I want to log the user's searches/database changes.
Does anyone have advice on how I can do this? I was thinking about adding a table for storing this information in the SQL Server database, but I am unsure how this would work for separation by different users. For example, if User A searches for "xyz" and User B searches for "Abc", when User A relaunches the site, the previous search history should only show "xyz"
EDIT: another question I thought of, if I were to create a table that follows this basic format:
Where the User column is a foreign column connecting to the Active Directory user (i.e. 3 -> John Smith and 7 -> Jane Doe), is it possible to connect a foreign key column representing which user made the changes in the site to an Active Directory group? That way if John Smith made a change in the site, when he logs in, any data that corresponds to only him is displayed?

How do I design a Login page for multiple databases in VB.NET

I am working on a company project, in which it contains a data processing system and this system was previously written separately for each bank and have their own project file, and each of the project has their own database that store the user credentials for them to login using their id and password.
Now we need to merge all the projects together so that it only login via a single login page, but i am wondering how am i going to do this because the data, especially the login credentials is stored in different databases. How should I pass data from a database to another database to perform validation?
Assuming these are SQL server logins, You will probably have to build a database with an availableDB table listing the available databases. Let the user choose a database, then try to open that database using the specified credentials, kicking him/her back to the choose-a-database point in the application.
If that doesn't answer your question, we'll need a little more information: architecture, desired interface, etc.
Hope this helps.
Why Dont You Use a drop down on login form with Every bank name listed in Drop Down. After selection of bank, use if and else statements to populate selected bank database.

MVC 4 Login and Policy on different DataBase

I'm trying to find a tutorial or help for solve this scenario.
In my MVC 4 application I want to have a Database where I store login information (username, password, connection strings ).
When User Login success, I want to open database with connection string stored in User Table, and get the policy from specific database (this database also contains the application data).
This means that a user can access to multiple database, and have different policy on every database.
Administrator can create a new user on Login Database, associate user with databases, and set policies for every Database.
Someone can help me or know a tutorial for doing that.
Thanks

Using Security Extension for certain reports only

My team has a service deployed internally, and part of this service is a list of client accounts stored in a sql table. SSRS is hosted on another server and we have integration jobs which [will eventually] pull these client accounts (along with additional info) from our 3 production environments to this SSRS database.
Also on this SSRS database, I’m creating a new table that will be a mapping of domain accounts and client accounts. I need this table so I can filter my report based on which client accounts the logged on user is allowed to see.
Pretty simple so far.
The next requirement of this is that I need to restrict access to the report itself. I understand I could normally use a security group to do this, but that would result in two separate locations to manage permissions for one resource and this is what I want to avoid.
The solution I’m looking into is to create a security extension to validate the logged in user against the database, allowing them access to the folder/report if they exist in the table. Once in, I can then use that same table again to filter their results.
What I’m not sure of is 1) if this is the best solution and 2) can I use a security extension for just MY portion of the site. There are many other users and reports on this site that I don’t deal with and don’t want to conflict with those.
Could you fill the DB table automatically from AD? Then you can use the standard windows security, but still only do the administration in Active Directory.
link text
You could set up an internal report parameter, called something like UserID, and set its default value to be the non-queried expression =User!UserID . (This user ID can be selected from the list of globals in the Edit Expression dialog.)
You could then add a cartesian/cross join to your users table in your query, with a selection condition based on your internal report parameter - eg. ...and UserTable.ID = #UserID . This would ensure that no records were returned if an unauthorised user was running the report.
Note that the User!UserID field will only return the user for interactively-run reports - in scheduled reports, this will be the account for the scheduling service.
Can't you restrict access to the report by using a security group (either in it's own folder or report level permissions). Use windows authentication in your datasource connection and filter you report retrieving your username using the sql function ORIGINAL_LOGIN?

Resources