Can someone point me in a right direction to learn how I can use a login form to login to SQLExpress Server using SQL Authentication
I am thinking that I would like to use the login for my app instead of embedding one in my application.
Is that wrong to thing like that
I am thinking right by using this to gain access to my application and login to the server at the same time
Davids Learning

Logins
pfd
OK hope you didnt see the earlier post , but
I feel like a dummy now.
How do you handle 3 connection strings
Davids Learning
Gerhardo
what is a good example, and where does she go
I got the login to function like it should, thanks again!
Is there a way to keep the form from melting away, looks kinda sick just fading out when the login completes.
Ah yea by the way do I have to call that in every form, or once your logged in does it take care of itself
Davids Learning
MuscleHead
Agreed.
In the login scenario we wouldn't expect there to be any large number of exceptions and the extra few milliseconds shouldn't be noticed. I just figured that as long as we were throwing some asides out there, we should cover all the bases.
Chad Campbell
One comment on Reed's suggestion of checking the ex.Message for a text string....
You can check for multiple exception objects within the Try block. For example:
Try
Conn.Open
'work with connection, etc.
Catch SqlErr as System.Data.SqlClient.SqlException
'in here you know an error specific to the SQL client occured
Catch ex as System.Exception
msgbox "Unexpected error: " & ex.message
End Try
The more information you can give your users, the eaiser your job will be ;)
progames25
OK, you can't hard code "LoginForm2.LoginName" inside of the connection string.
The connection string should initially end with ".mdf". There should be no username or password in the connection string that is stored in My.Settings.
After the call to:
My.Forms.LoginForm2.ShowDialog()
add the lines:
Dim NewConStr As String
NewConStr = String.Format("{0};UID={1};PWD={2}", My.Settings.ConnectionString, LoginForm2.LoginName, LoginForm2.Password)
Me.COFTableAdapter.Connection.ConnectionString = NewConStr
then you can make the call to:
Me.COFTableAdapter.Fill(Me.DataSet1.COF)
In the code above, "My.Settings.ConnectionString" will be replaced with the name of the stored connection string setting. The String.Format() method is going to replace each of the {} items with the values supplied after the string.
qrli
Well, to specify the user account using SQL Authentication, you just set the username and password on the connection in code before calling any methods that would open the connection. That account has to exist in SQL. If the username and password are the same it both SQL and the application then you can pass the same login info from the app to the database.
You kind of lost me with the "use the login for my app instead of embedding one in my application"... I'm not sure if this means that you already have a login form for you application and don't want to create a seperate form for SQL, but that's how I'm taking it.
You can certianly do this - you'll just have to keep the accounts synchronized. You might watch for a database login failure error and respond by give the user an opportunity to change the password in the database.
schveiguy
As usual, you have several options.
You could implement a property on the LoginForm to get the values; but this probably isn't necessary as the controls on the form are already accessible (unless you've changed the modifer from Friend). So you could just say: loggeduser = LoginForm.TextBox1.Text
More likely though, you'll want to cache this info in your app (it can be argued that you shouldn't cache passwords but in this case it should be fine). So you might add two strings to your My.Settings collection called CurrentUser and CurrentPassword. Then after authenticating the user on the login form, you store the credentials in those string settings. Now you can access them whenever you want - to log into the database, or just to have a label display "Welcome Username!".
Lawrence Parker
Richard is correct; his example will give you an exception object with more SQL specific detail.
However, you'll still need to check the SqlException object to determine the type of error (e.g. perhaps the database isn't available). With the SqlException there is a Number property that you could test for 18456, which would be the login failed error number.
Keep in mind that generating exceptions is expensive, and casting the exception into a derived type increases the expense. In this case, catching the System.Exception will be several milliseconds faster than catching the SqlClient.SqlException.
Amnesyc
ShadowOfTheBeast
Does your application already have a login mechanisim If not, then do as you say and add one that occurs during the app startup. Handle authenticating the user into your app. Then add the current username and password to the connection string. The connection string should be store in My.Settings. While it's not written in Basic, it is easy to parse. Just modify the value by removing the "User Id= xxxxx;" part. Then, in code, you set the TableAdapter.Connection.ConnectionString = My.Settings.ConnectionString & ";User Id = loggeduser; Password = suppliedpassword" where "loggeduser" and "suppliedpassword" are the username and password from the application login. Now you can call the Fill() method on the TableAdapter, using the current user's credentials.
Now, whenever you allow the user to change their password in the application, you must also use the System.Data.SqlClient.SqlConnection.ChangePassword() method to update the database password.
You can catch a login error by performing your TableAdapter.Fill() method within a Try-Catch block. You can test the exception message to see if it is a login error: If ex.Message.StartsWith("Login failed for user") Then.
HTH
ron nash
Remember, everything is a class. Add a couple of properties to your login form:
Public Property LoginName() As String
Get
LoginName = Textbox1.Text
End Get
Set (byval value as string)
Textbox1.Text = Value
End Set
End Property
Then you can reference the properties from your other form:
ConnString = ConnString & "User ID = " & LoginForm.LoginName & ";"
ConnString = ConnString & "Password = " & LoginForm.Password & ";"
RobLearningVisualBasic
User Id = loggeduser; Password = suppliedpassword"
how do you pass that from the login form
Davids Learning
nub340
just set the username and password on the connection in code
do you mean pass the user info from the dialog to your connection string
if so how would you add it, i have looked at the connection string code and it dont look like vb to me
so basically what i think your saying is have a dialog that is modal when your main form opens, pass the info from there to SQL.
How do you catch the fail if what they enter is not right
Thanks for helping
Davids Learning
OOMama
Having a little problem
I made the classes like you said
made a msgbox to show me the results - there fine - thank you for teaching me that by the way.
but when I go to my connection string I run into a problem
what you gave didnt work - it said that & was an illegal operand i think
and it fused about User ID
anyhow I tried this
this is the end of my conn string .mdf;UID=LoginForm2.LoginName;Pwd=LoginForm2.Password
"It failed, it said login failed for "LoginForm2.LoginName"
I did make my loginform2.showdialog
I put this in the mainform's on load event - the last line was already there
My.Forms.LoginForm2.ShowDialog()
Me.COFTableAdapter.Fill(Me.DataSet1.COF)
Can you help with this
Davids Learning