Client - Sql Server 2000 Server

1

my question is presented, in Sql Server 2000 and Vb6, what I want to do is access with my application to the PC-server from the PC-client to access the data of the database. How do I make that connection? Where do I start ?, Thank you very much and sorry, I know little about the data I leave, greetings.

    
asked by Rober Sonda 18.11.2016 в 19:32
source

2 answers

4

This may be a way of doing it, although there are others (I had to dust off the code a bit).

To connect with SQL Server 2000 and VB 6 , the most common thing is to use a ADOdb object. The connection is armed with a connection string that you would have to modify to your needs.

Once the connection is established, you can consult the data with a recordset object.

    Dim MyConnObj As ADODB.Connection ' Objecto ADODB Connection
    Dim myRecSet As New ADODB.Recordset 'Objeto Recordset
    Dim sqlStr As String ' String variable para almacenar la consulta a la base

    Set MyConnObj = New ADODB.Connection

    MyConnObj.ConnectionString = "Provider=sqloledb;Data Source=IPServidor;Initial Catalog=NombreBaseDeDatos;User Id=Usuario;Password=Password;"

    MyConnObj.Open

    Set myRecSet = New ADODB.Recordset

    sqlStr = "select * from Empleados"

    myRecSet.Open sqlStr, MyConnObj, adOpenKeyset
    
answered by 18.11.2016 / 19:47
source
1

To make the connection you can implement it in a module something like:

Attribute VB_Name = "Conexion"
Option Explicit
Public cn As ADODB.Connection
Public rs As ADODB.Recordset

Public Sub Conectar()
  Set cn = New ADODB.Connection
  Set rs = New ADODB.Recordset
  rs.CursorLocation = adUseClient
  cn.Open "Provider=SQLNCLI11;Server=.;Database=DBPrueba;Uid=sa;Pwd=666;"
End Sub

Public Sub Desconectar()
  On Error Resume Next
  rs.Close
  Set rs = Nothing
  cn.Close
  Set cn = Nothing
End Sub

Using this connection

Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword;

You can follow SQL Serverver 2000 connection strings

You can use it from a Client Class:

Public Function GetCliente() As ADODB.Recordset
  Dim rs As ADODB.Recordset
  Dim strSQL As String
  Conectar
  strSQL = "SELECT idCliente AS Código, nombre AS Nombre FROM Clientes"
  Set rs = New ADODB.Recordset
  rs.Open strSQL, cn, adOpenStatic, adLockOptimistic
  Set GetCliente = rs
End Function

The code is example you must adapt it to your needs.

    
answered by 22.11.2016 в 23:55