Как подключить удаленную базу данных SQL в visual basic 2017 и SQL express 2014
Привет, я работаю над своим магазинным проектом приложения visual basic windows form ,которое должно использовать 5 различных ПК ,1 для магазина ,2 для склада и 3,4 , 5 для биллинга учета и администрирования использования , я создаю это приложение на базе tcp клиент-сервер и используется для sql control class для подключения базы данных SQL, это работает только на рабочем столе должным образом, но не связано с другим ПК
когда я пытаюсь удаленно подключиться к базе данных SQL это не может работать нужна помощь
как я удаленно подключаюсь к своей базе данных
Что я уже пробовал:
это и есть SQL контроль
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
это форма 1, которую я хочу подключить к базе данных
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