Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB.NET
Imports System.Data.SqlClient
Imports System.Linq
Imports System.Data




Public Class Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Dim conn As SqlConnection
        'Dim cmd As SqlCommand
        Dim rd As SqlDataReader
        Dim conn As New SqlConnection()
        Dim cmd As New SqlCommand()
        conn.ConnectionString = "Data Source=localhost;Initial Catalog=user;Integrated security=true"
        cmd.Connection = conn
        conn.Open()
        cmd.CommandText = "Select login,password from user where login='" & TextBox1.Text & "'and password='" & TextBox2.Text & "'"
        rd = cmd.ExecuteReader
        If rd.HasRows Then
            Welcome.Show()
        Else
            MsgBox("Invalid Login or Password")
        End If

    End Sub
End Class
Posted
Updated 24-Jan-16 0:36am
v2
Comments
Kornfeld Eliyahu Peter 24-Jan-16 6:34am    
How can we know?!
We do not know where the database is. We do not know what it called. We do no know, who should have access...
We do not know!

We can't tell you that - because we don't know. The connection string changes for each installation to match the actual SQL instance, database, login method, username, and password that applies for that setup.

What you can do is try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.
 
Share this answer
 
As a complement to OriginalGriff's answer there is a site dedicated to connection strings that you should check out.

ConnectionStrings.com - Forgot that connection string? Get it here![^]

And specifically for SQL server: SQL Server connection strings - ConnectionStrings.com[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900