[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Connect via ip to an SQL database within a VB6 app

Posted on 2005-04-11
5
Medium Priority
?
322 Views
Last Modified: 2013-12-25
Greetings,

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

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

Is that possible in VB6?

Thanks,

--- Mike
0
Comment
Question by:MikeCombe
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 13759741
   *  Connect via an IP address:
      "Provider=sqloledb;Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 13763078
To expand on Dhaest answer form http://www.able-consulting.com/MDAC/ADO/Connection/OLEDB_Providers.htm#OLEDBProviderForSQLServer:

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

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

Expert Comment

by:rdwillett
ID: 13787191
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 = 100.100.100.100" 'Put Your IP Here

    'For Windows Authentication use this (comment out or delete the one you don't use)
        sconnstring = _
                "Provider=sqloledb;" & _
                "Data Source=100.100.100.100;" & _   '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
            conn.Close
    End IF
   
    Exit Sub
err_connection:
    MsgBox Err.Description, vbInformation
End Sub

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

867 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