dynamic username and password in connection string

adshocker

Well-known member
Joined
Jun 30, 2007
Messages
180
Programming Experience
Beginner
hi,

im using oracle10gxe as my database. i've created 2 users. user1 and user2 for example.

then on my vb.net application, i created a connectionstring using the Add New Datasource Wizard. then on my app.config i can see the username i've placed during the wizard.

however, i need to create a login screen but dont have any idea where to start.

on my login_click button
VB.NET:
My.Settings.Item("ConnectionString") = "My connection string"

but how do i open the connection or how do i test if the username and password are valid?
 
VB.NET:
Dim builder As New OracleConnectionStringBuilder(myConnectionString)

builder.UserID = userID
builder.Password = password

myConnectionString = builder.ConnectionString
 
set your connection string to something like this:

constr="blah blah; username=uname; password=pword"

then at runtime, use Replace method to replace uname and pword with the real info.

thanks for the suggestion.
i'm not familiar with the replace method so what i did was this.

VB.NET:
My.Settings.Item("ConnectionString") = "Data Source=YourOracleDB;User Id=" & txtUsername.Text & ";Password=" & txtPassword.Text" & ";Integrated Security=no;"

but i have no idea on how the application will check if the username and password are valid/correct.
any suggestions?
 
VB.NET:
Dim builder As New OracleConnectionStringBuilder(myConnectionString)

builder.UserID = userID
builder.Password = password

myConnectionString = builder.ConnectionString

i'm gonna try this... thanks.
by the way, does this automatically check if the username and password are valid?
because i'm having a problem with that as well
 
Last edited:
you can't check whether un/pw are valid unless you have something to compare them with... the only thing you can do is to pass them in, let the little oracle thingy does its thing and tell you whether it can connect or not.

If it can connection, credentials are valid and bad if otherwise.
 

thanks for the insight... i've read the thread here... still having a hard time understanding for now but i will later on.

now my concern here is that if a user changes the connection string in the XML, will it affect other users that are currently logged in? i'm guessing this is where the User Scope comes in handy but i don't quite get how to do it just yet.

you can't check whether un/pw are valid unless you have something to compare them with... the only thing you can do is to pass them in, let the little oracle thingy does its thing and tell you whether it can connect or not.

If it can connection, credentials are valid and bad if otherwise.

thanks... this was easy enough.. :)
 
i would just like to add that what i'm trying to do basically is to create an application that initially asks for a username/password (login screen). since many users can login to the same application at the same time, i fear that changing the connectionstring in the MySettings won't be such a good idea.

does anyone have any ideas on how i can go about this?
thanks...
 
i've learned how to use the oracle string builder based on your suggestion... but i have a few questions though since i dont have a 2nd and 3rd pc to try it on.

1. will it work if i'm using a typed dataset?
2. will it not affect other users connected?
3. will it work if i'm gonna use ClickOnce as my deployment strategy?

many thanks...
 
thanks for the insight... i've read the thread here... still having a hard time understanding for now but i will later on.

now my concern here is that if a user changes the connection string in the XML, will it affect other users that are currently logged in?
if "currently logged in" means "running your app" then no. if it means logged into windows and have yet to start the app, then yes.

i'm guessing this is where the User Scope comes in handy but i don't quite get how to do it just yet.

user scope makes it editable programmatically
 
i would just like to add that what i'm trying to do basically is to create an application that initially asks for a username/password (login screen). since many users can login to the same application at the same time, i fear that changing the connectionstring in the MySettings won't be such a good idea.

does anyone have any ideas on how i can go about this?
thanks...

Yeah, normally we actually have a table with username and a hashed password and use just one user for the database. THis is because setting up 100 oracle users to ahve all the necessary permissions is a pain in the arse
 
Back
Top