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