none
How to detect connected computers in a LAN using visual basic and connect it using a client application

    Question

  • Hello,

    I would like to ask how to connect our application to connected computers in a LAN.
    Will I use the winsock control?

    How can I run queries using a server database?

    Any answers are welcome.

    Please, I need help.SOS..
    Tuesday, March 10, 2009 7:26 AM

Answers

  • Wizard-In-Disguise said:

    I would like to ask
    how to connect our application to connected computers in a LAN.
    Will I use the winsock control?

    How can I run queries using a server database?

    Hi,

    Welcome to MSDN forums!

    1. Yes, you can connect and communicate with other machines via WinSock control.
        
    However, .NET has native implementation for socket communication. The namespace System.Net.Sockets contains most of the objects required for socket communication.

    Here is one good source-opened Chat application example via 
    System.Net.Sockets namespace in Microsoft website for you to download and refer to.

    Creating a Multi-User TCP Chat Application
    http://msdn2.microsoft.com/en-us/library/aa478452.aspx


    It's written in VB.NET. Download the Vbsockets.exe sample file, then run and unzip it, you will find two projects: SocketClient and SocketServer.



     


    2. You can connect and access SQL Server database (the SQL Server machine can be at local machine or LAN machines) in VB.NET.

    Code sample: Connect to SQL Server database and retrieve table records to DataGridView. 

    Imports System.Data.SqlClient  
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim con As SqlConnection = New SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;")  
            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Table1", con)  
            con.Open()  
            Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)  
            Dim myDataSet As DataSet = New DataSet()  
            myDA.Fill(myDataSet, "MyTable")  
            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView  
            con.Close()  
            con = Nothing 
        End Sub 
     
    End Class 



    Best regards,
    Martin Xie

    Friday, March 13, 2009 5:18 AM

All replies

  • Wizard-In-Disguise said:

    I would like to ask
    how to connect our application to connected computers in a LAN.
    Will I use the winsock control?

    How can I run queries using a server database?

    Hi,

    Welcome to MSDN forums!

    1. Yes, you can connect and communicate with other machines via WinSock control.
        
    However, .NET has native implementation for socket communication. The namespace System.Net.Sockets contains most of the objects required for socket communication.

    Here is one good source-opened Chat application example via 
    System.Net.Sockets namespace in Microsoft website for you to download and refer to.

    Creating a Multi-User TCP Chat Application
    http://msdn2.microsoft.com/en-us/library/aa478452.aspx


    It's written in VB.NET. Download the Vbsockets.exe sample file, then run and unzip it, you will find two projects: SocketClient and SocketServer.



     


    2. You can connect and access SQL Server database (the SQL Server machine can be at local machine or LAN machines) in VB.NET.

    Code sample: Connect to SQL Server database and retrieve table records to DataGridView. 

    Imports System.Data.SqlClient  
     
    Public Class Form1  
     
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim con As SqlConnection = New SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;")  
            Dim cmd As SqlCommand = New SqlCommand("SELECT * FROM Table1", con)  
            con.Open()  
            Dim myDA As SqlDataAdapter = New SqlDataAdapter(cmd)  
            Dim myDataSet As DataSet = New DataSet()  
            myDA.Fill(myDataSet, "MyTable")  
            DataGridView1.DataSource = myDataSet.Tables("MyTable").DefaultView  
            con.Close()  
            con = Nothing 
        End Sub 
     
    End Class 



    Best regards,
    Martin Xie

    Friday, March 13, 2009 5:18 AM
  • Hello, I want to ask how to connect database in LAN using VB.Net
    I'm Developing 2 applications, which are Client application and Server application. I'm using SQL server 2005 management studio express for the database, and it is stored in the Server application. And I'm using Winsock control to communicate between 2 applications, and it's already connected successfully.

    The question is how can I connect retrieve the database information which is stored in Server application.


    Based on Mr. Martin Xie post the code above, I followed the code and change the "Data Source=STEWARD\SQLEXPRESS;Initial Catalog=Server", but in my Client application still cannot retrieve the data from database(Server Apllication).

    Any answers are welcome, Please help me....

    Thanks....
    Thursday, June 04, 2009 2:20 PM
  • steward try to use the ip address of your server instead the name of the sqlserver like for example "Data Source=192.168.1.1;Initial Catalog=Server"

     

    regards

    Thursday, March 17, 2011 11:44 AM