Hi guys,

I have developed a windows application using vb.net 2012 and sqlserver express edition 2012. the application is able to access the database on a local hot computer. but when I take it to another compter on the same domain (networ). it is throwing the following error "Cannot open database 'Returnables' requested by log in. log in failed for user 'Lubambe\chaavwan.

Note: Returnables is the name of the database on the other computer where SQL server is installed, Lubambe is the name of the domain and chaavwan is a user name on the client computer.
Note: The name of the server is SECURITY1 and the name of the client computer is SECURITY-PC.
Below is the code I am using.

Imports System.Data
Imports System.Data.SqlClient
Public Class frmLogIn

    Private Sub frmLogIn_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Dim MyConnection As SqlConnection = New SqlConnection("Server=SECURITY1;Initial Catalog=Returnables;Trusted_Connection=True")
            MyConnection.Open()
            Dim strSQL As String = "SELECT ID FROM tblUsers"
            Dim da As New System.Data.SqlClient.SqlDataAdapter(strSQL, MyConnection)
            Dim ds As New DataSet
            da.Fill(ds, "tblUsers")

            With Me.cmbUser
                .DataSource = ds.Tables("tblUsers")
                .DisplayMember = "ID"
                .ValueMember = "ID"
                .AutoCompleteMode = AutoCompleteMode.SuggestAppend
                .AutoCompleteSource = AutoCompleteSource.ListItems
            End With

            MyConnection.Close()
            cmbUser.Text = ""
            lblusertype.Text = ""

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub cmbUser_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbUser.SelectedIndexChanged
        Try
            Dim cn As New SqlClient.SqlConnection("Server=SECURITY1;Initial Catalog=Returnables;Trusted_Connection=True")
            Dim tbl As New DataTable
            Dim da As New SqlClient.SqlDataAdapter

            cn.Open()
            Dim query As String

            query = "SELECT UserType " & " FROM tblUsers " & " WHERE ID = '" & cmbUser.Text.ToString & "'"

            Dim cmd As New SqlCommand(query, cn)

            Dim rdr As SqlDataReader = cmd.ExecuteReader()

            If rdr.Read Then
                lblusertype.Text = rdr.GetString(0)

                cn.Close()

            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Try
            Dim cn As New SqlClient.SqlConnection("Server=SECURITY1;Initial Catalog=Returnables;Trusted_Connection=True")
            Dim query As String

            query = "SELECT ID,Password FROM tblUsers WHERE (ID = '" & cmbUser.Text & "' ) AND (Password = '" & txtPass.Text & "')"

            Dim cmd As New SqlCommand(query, cn)

            'cmd.Parameters.AddWithValue("ID", Me.cmbUser.Text)
            'cmd.Parameters.AddWithValue("Password", Me.txtPass.Text)

            cn.Open()
            Dim read As SqlDataReader = cmd.ExecuteReader()

            If read.HasRows Then

                read.Read()

                If Me.cmbUser.Text.ToLower() = read.Item("ID").ToString And Me.txtPass.Text.ToLower = read.Item("Password").ToString Then

                    frmMenu.Show()
                    Me.Hide()
                    txtPass.Text = ""

                End If

            Else
                MsgBox("Sorry, Acces Denied, Invalid ID or Password", MsgBoxStyle.OkOnly, "Caution")

                txtPass.Text = ""

            End If
            read.Close()

            cn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

Thanks in advance

When you take your app to another PC, what SQL server did you install there?

That is, I've yet to see vb.net's installer install the server for me. I have to add that.

As to the connection string, you HARDCODED that. Seems this is your first rodeo so next time add some screens to your app (most folk call it Settings) to allow customization of the app for each install instance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.