SQL - conxion a Sql Server 2014 desde Ms Access

 
Vista:
sin imagen de perfil
Val: 1
Ha disminuido su posición en 42 puestos en SQL (en relación al último mes)
Gráfica de SQL

conxion a Sql Server 2014 desde Ms Access

Publicado por pedro eduardo (1 intervención) el 14/10/2017 19:10:47
Agradeceré quien me pueda dar una ayuda.

Necesito conectarme a SQL Server 2014 desde Ms Access 2010 con el siguiente código pero no me funciona

ALGUIEN ME PUEDE INDICAR PORQUE NO ME TRAE LOS DATOS.
DESDE YA MUCHAS GRACIAS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function CONECTAR2014 ()
 
On Error GoTo AdmErr
Dim StrServidor As String
Dim StrBdatos As String
CONECTAR2014 = False
 
StrServidor = "DESKTOP-THOMBBM\SQLEXPRESS"
StrBdatos = "SGAPDATO"
 
Set gCon = New ADODB.Connection
 
Dim StrCon As String
StrCon = "Provider=SQLOLEDB;Data Source=" & StrServidor & "; Initial Catalog=" & StrBdatos & ";Connection Timeout=300;"
 
Trusted_Connection = True
 
On Error Resume Next
Err.Clear
gCon.Open StrCon
 
 
If Err.Number > 0 Then
    gStrUltError = "Error al conectarse a servidor " & Err.Description
    GoTo Salir
End If
 
'On Error GoTo AdmErr
Dim RstDet As ADODB.Recordset
Set RstDet = Nothing
Set RstDet = New ADODB.Recordset

gStrSQL = "select * from dbo.TBLZCARGO;"


RstDet.Open gStrSQL, gCon, adOpenStatic, adLockReadOnly
While Not RstDet.EOF
'
    Debug.Print RstDet("Id"): Debug.Print RstDet("Cargo")
    RstDet.MoveNext
Wend
 
 
CONECTAR2014 = True
Salir:
    Exit Function
 
AdmErr:
    gStrUltError = "Error al conectarse " & Err.Description
 
End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder