Sunday, February 12, 2012

Connecting to SQL Server with a login form.

Hi all,

I'm new to VB and VB.net and forms and everything, so please bare with me :)

I am constructing an application which is connected to sql server 2000. What I want to do is have the Login form open upon startup then have an option group where the user states if he wants to use NT or SQL Server authentication. . Then I want a combobox which looks up all the current sql servers there are on the network, so that the user chooses the sql server that it connects to. or if that's not possible, just a textbox with the sql server and database name.

I already have the option group (although I don't know how to get their values, I worked with plain old MS Access before this)

#1: What will my connection string look like?
#2: How will I tell my application which type the user selected?
#3: How can I save the credentials in my application when the user logs in so that I can use that credentials throughout the application?

Thanks

Rudi



if (rdoUseSqlAuth.Checked==true)
{
// user chose sql auth
}
else if (rdoUseWindowsAuth.Checked==true)
{
/// user chose windows auth
}


http://www.connectionstrings.com for information about connection strings
To save the information and be able to use it throughout the class you may look at use the Singleton class model
you would copy their code snippet and simply add public members or properties to store your information in.
|||Hi Marc,

Thanks for the help, but I don't have a clue how to use that singletone thing. How would I go about making the connection public and carrying over the connection string to main main form (MDI Container) and then use it in my mdi child forms?

Another thing, I'm battling this stupid as to when clicking the login button to get the login box closed (not hidden) and opening the main form. Up until now the main form flashes on the screen and the application ends.

Any ideas?

btw, I'm using vb.net as my language.

Thanks|||Your form is disappearing probably because whenever the startup form is closed that signals the application to exit.

|||

Dear MarcD,

If i'm using MS Access as my database..
Will I need sum ting as tis too?

if (rdoUseSqlAuth.Checked==true)
{
// user chose sql auth
}
else if (rdoUseWindowsAuth.Checked==true)
{
/// user chose windows auth
}

And I do not know how to code my login verification.
Please giv sum guide!

Thanks & GOD bless!
Jesse

|||

In case of sqlserver we are having differnt types of values for connection for examle

con.connectionstring=" Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=sridb;Data Source=xvz;"

ok

Ur 2nd ?

Regarding the type of user u want to select

We are having (Windows) Principal and permission classes U have to include the libraries and u have to write the code

Dim MyIdentity As WindowsIdentity = WindowsIdentity.GetCurrent()

'Put the previous identity into a principal object.
Dim MyPrincipal As New WindowsPrincipal(MyIdentity)

'Principal values.
Dim PrincipalName As String = MyPrincipal.Identity.Name
Dim PrincipalType As String = MyPrincipal.Identity.AuthenticationType
Dim PrincipalAuth As String = MyPrincipal.Identity.IsAuthenticated.ToString()

'Identity values.
Dim IdentName As String = MyIdentity.Name
Dim IdentType As String = MyIdentity.AuthenticationType
Dim IdentIsAuth As String = MyIdentity.IsAuthenticated.ToString()
Dim IsG As String = MyIdentity.IsGuest.ToString()
Dim IsSys As String = MyIdentity.IsSystem.ToString()
Dim Token As String = MyIdentity.Token.ToString()

No comments:

Post a Comment