Connect via ip to an SQL database within a VB6 app

Posted on 2005-04-11
Last Modified: 2013-12-25

Here's what I would like to do....

Create a VB6 app.
Connect via ip to an SQL database.

Is that possible in VB6?


--- Mike
Question by:MikeCombe
    LVL 53

    Accepted Solution

       *  Connect via an IP address:
          "Provider=sqloledb;Data Source=,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
    LVL 29

    Expert Comment

    To expand on Dhaest answer form

    To connect to SQL Server running on a remote computer (via an IP address)

    oConn.Open "Provider=sqloledb;" & _
               "Network Library=DBMSSOCN;" & _
               "Data,1433;" & _
               "Initial Catalog=myDatabaseName;" & _
               "User ID=myUsername;" & _
    - "Network Library=DBMSSOCN" tells OLE DB to use TCP/IP rather than
       Named Pipes (Q238949)
    - is an IP address
    - 1433 is the default port number for SQL Server.  Q269882 and Q287932
    - You can also add "Encrypt=yes" for encryption
    LVL 4

    Expert Comment

    I just use the same code to connect by name or ip and have found that it works the same.  Try below and let me know if it works.

    Add a reference to the Microsoft ActiveX Data Objects 2.x Library under Project-->References
    Add one Command Button named Command1 (default name)
    Add the following code (changing it to match your ip and user properties -- userid -- password-- database name)

    Public Sub Command1_Click()
        On Error GoTo err_connection
        Dim conn As New ADODB.Connection
        Dim sconnstring As String
        'For sql Authentication use this (comment out or delete the one you don't use)
        sconnstring = _
                "Provider=SQLOLEDB.1;" & _
                "User ID=MyID;" & _
                "Password=MyPassword;" & _
                "Initial Catalog=MySqlDatabase;" & _
                "Data Source =" 'Put Your IP Here

        'For Windows Authentication use this (comment out or delete the one you don't use)
            sconnstring = _
                    "Provider=sqloledb;" & _
                    "Data Source=;" & _   'Put Your IP Here
                    "Initial Catalog=MySqlDatabase;" & _
                    "Integrated Security=SSPI;" & _
                    "Connect TimeOut = 1000"
        conn.Open sconnstring
        If conn.State = adStateOpen Then
                Msgbox "I opened my database with an IP Address", vbInformation
        End IF
        Exit Sub
        MsgBox Err.Description, vbInformation
    End Sub


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now