-1

In asp.net 4.0 c#, i have two databases on different servers 1.Sql server 2.Oracle

I want to develop a web application in which the users will login with their id password and then perform the allowed tasks.

I want to know that how i can make a single connection string for multiple users? I dont want to make connection string on every page.

I was looking for this for a whole day but could not found any solution. currently i am not using web.config file but i have a class where i have made a connection string and passed the textbox values to it and the storing them in static fields and suppling them to other classes , but i dont think it is good approach

i think most of people are not getting what i really want to ask kindly let me know if you want any confirmation.

for example there are 40 users each having a different id,password (no of users can be increased or decreased) there are two approaches to have a connection string 1)make a connection string in a class string conn=@"server=MYSERVER;database=mydb;user id="+userid+";password="+password); but how the userid,password fields can be accessed in web.config? here userid=textbox1.text,,password=textbox2.text;

2)make a connection string in a web.config file so how?

2
  • Usually this question asked in opposite way - "how to specify connection string unique/different for each user". Have you tried to see how to set connection string in ASP.Net application in general? Or you have some problem not covered by normal web.Config setting (like stackoverflow.com/questions/5642474/…) - please clarify. Commented Feb 28, 2014 at 19:59
  • @TusharGupta i have been searching for this a whole day but could not find a thing what i want.I have made some edits in my question so kindly let me know if you want any more details Commented Feb 28, 2014 at 20:08

1 Answer 1

1

It is very common for all users to use the same connection string to talk to the database server for a web application, and for the application to control what functions the users can and can't do based on their userid and password and security you build into you application.

In this type of setup, the user's id and password are separate (and different) from the userid and password for the database server.

If you must use a separate userid and password for each users db connection, then you wouldn't store it in a connection string in your config file, but would instead build it dynamically based on the user logging in.

Like this for example:

var userid = "testuser";  //these would come from your login page, not hardcoded
var password = "letmein";

var sqlConn = new SQLConnection("server=MYSERVER;database=mydb;user id="+userid+";password="+password);
Sign up to request clarification or add additional context in comments.

13 Comments

If i have a web.config file then i can supply only one id and password in it so how can i use it for different users?
You build a login page in you application and control what they can do thru your application logic, not the database permissions. For example, Facebook uses a database, you login to Facebook with a userid and password, but I guarantee you Facebook is not using your userid and password to connect to their database- the security is instead built into the application.
i have the same connection string which you have given as an example.But how i can access the userid and password fields in web.config because they are not accessible in web.confg
String.Format may provide more readable code (...id={0};password={1}) keeping the same SQL injection issues... I.e. with Web.Config one can do something like String.Format(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionStrin‌​g, userId, password)
@raz I thought you wanted a single connection string? Maybe I'm not understanding your question; how can a different connection string for each user be considered a single connection string?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.