Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i am working on my shop project of visual basic windows form application which need to uses 5 different PC ,1 for store ,2 for warehouse and 3 ,4,5 for billing accounting and admin use , i am creating this application on tcp client server base and used to sql control class to connect SQL database , it's only works on desktop properly but not connected with another PC
when i am trying to connect remotely to SQL data base it's could not works need help
how i connect remotely with my database

What I have tried:

this is SQL control

Imports System.Data.SqlClient
Public Class Sql_control
    Public DBCon As New SqlConnection("Data Source=DEV-ASUS\SQLEXPRESS,1433;Network Library=DBMSSOCN;Server=DEV-ASUS\SQLEXPRESS;Database=Buss_db;trusted_connection=true;")
    '
    Private DBCmd As SqlCommand

    ' DB DATA
    Public DBDA As SqlDataAdapter
    Public DBDT As DataTable

    ' QUERY PARAMETERS
    Public Params As New List(Of SqlParameter)

    ' QUERY STATISTICS
    Public RecordCount As Integer
    Public Exception As String

    Public Sub New()
    End Sub

    ' ALLOW CONNECTION STRING OVERRIDE
    Public Sub New(ConnectionString As String)
        DBCon = New SqlConnection(ConnectionString)
    End Sub

    ' EXECUTE QUERY SUB
    Public Sub ExecQuery(Query As String)
        ' RESET QUERY STATS
        RecordCount = 0
        Exception = ""

        Try
            DBCon.Open()
            If DBCon.State = ConnectionState.Open Then MsgBox("open")
            ' CREATE DB COMMAND
            DBCmd = New SqlCommand(Query, DBCon)

            ' LOAD PARAMS INTO DB COMMAND
            Params.ForEach(Sub(p) DBCmd.Parameters.Add(p))

            ' CLEAR PARAM LIST
            Params.Clear()

            ' EXECUTE COMMAND & FILL DATASET
            DBDT = New DataTable
            DBDA = New SqlDataAdapter(DBCmd)
            RecordCount = DBDA.Fill(DBDT)
        Catch ex As Exception
            ' CAPTURE ERROR
            Exception = "ExecQuery Error: " & vbNewLine & ex.Message
        Finally
            ' CLOSE CONNECTION
            If DBCon.State = ConnectionState.Open Then DBCon.Close()
        End Try
    End Sub

    ' ADD PARAMS
    Public Sub AddParam(Name As String, Value As Object)
        Dim NewParam As New SqlParameter(Name, Value)
        Params.Add(NewParam)
    End Sub

    ' ERROR CHECKING
    Public Function HasException(Optional Report As Boolean = False) As Boolean
        If String.IsNullOrEmpty(Exception) Then Return False
        If Report = True Then MsgBox(Exception, MsgBoxStyle.Critical, "Exception:")
        Return True
    End Function
End Class



this is form 1 that i want connect with database

Public Class Form1
    Private sql As New Sql_control
    Private Client As TCPControl

    Dim yv_msg As Integer = 1
    Private Sub cmdSend_Click(sender As System.Object, e As System.EventArgs) Handles cmdSend.Click
        SendMessage()
        txtMessage.Clear()

    End Sub

    Private Sub cmdConnect_Click(sender As System.Object, e As System.EventArgs) Handles cmdConnect.Click
        Client = New TCPControl("192.168.43.239", 8888)
        If Client.Client.Connected Then cmdConnect.Text = "Connected"
        TxtMessage.Text = yv_msg & Space(2) & "Data Lode"
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Client.Client.Connected = True Then
            Client.DataStream.Close()
            Client.Client.Close()
        End If
    End Sub

    Private Sub txtMessage_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtMessage.KeyDown
        If e.KeyCode = Keys.Enter Then SendMessage()
    End Sub

    Private Sub SendMessage()
        If Client.Client.Connected = True Then
            Client.Send(TxtMessage.Text)

        End If
    End Sub
    Public UpdateText As String = ""
    Private Sub OnLineReceived(sender As TCPControl, Data As String)
        ' UpdateText(Data)
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Txtuserid_KeyDown(sender As Object, e As KeyEventArgs) Handles Txtuserid.KeyDown
        If e.KeyCode = Keys.Enter Then
            If String.IsNullOrEmpty(Txtuserid.Text) Then
                MsgBox("Invalid Input ")
                Txtuserid.Clear()
                Txtuserid.Select()
            End If
            If Not String.IsNullOrEmpty(Txtuserid.Text) Then
                TxtPAssword.Select()
            End If
        End If
    End Sub

    Private Sub TxtPAssword_KeyDown(sender As Object, e As KeyEventArgs) Handles TxtPAssword.KeyDown
        If e.KeyCode = Keys.Enter Then
            If String.IsNullOrEmpty(TxtPAssword.Text) Then
                MsgBox("Invalid Input ")
                TxtPAssword.Clear()
                TxtPAssword.Select()
            End If
            If Not String.IsNullOrEmpty(TxtPAssword.Text) Then
                Cmd_log.Select()
            End If
        End If
    End Sub
    Dim m_name As String = ""
    Dim L_name As String = ""
    Private Sub Cmd_log_Click(sender As Object, e As EventArgs) Handles Cmd_log.Click

        sql.AddParam("@a1", Txtuserid.Text)
        sql.AddParam("@a2", TxtPAssword.Text)
        sql.ExecQuery("Select username,password,name,lastname from user1 where username=@a1 and password=@a2  ")
        If sql.RecordCount < 1 Then MsgBox("No data found as per your requiest ") : Exit Sub
        Dim r As DataRow = sql.DBDT.Rows(0)
        m_name = r("name").ToString
        L_name = r("lastname").ToString
        MsgBox(" you Log as " & Space(2) & m_name & Space(2) & L_name)

        'username,password,name,lastname     :user1
    End Sub
End Class
Posted
Updated 23-Feb-18 3:48am

As I recall, if you are using SQLServer Express, you cannot connect to it from a remote computer; it will only connect from the computer it is installed on.

So.. if you want to use SQLServer, you either need to use a full version (not an Express version) or write a application on your host PC that will process all database requests for you.
 
Share this answer
 
Comments
RickZeeland 23-Feb-18 13:02pm    
I think you are confusing LocalDb with SQL Server Express !
See: https://stackoverflow.com/questions/11278114/enable-remote-connections-for-sql-server-express-2012
Tim Carmichael 23-Feb-18 13:17pm    
As I started in my comment... "As I recall"; that may have changed with later versions, but it used to be a case of an Express system could not be connected to remotely.
The DBA where I worked copied a DLL from a 'regular' system to enable the functionality.. but that is a whole different matter.
 
Share this answer
 
Comments
yogesh vaidya 23-Feb-18 13:56pm    
thanks sir ,
for your valuable guidance .
yogesh..

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