Coneccion ODBC

Tengo una aplicación desarrollada en VB6 con SP5 y trabajo en ADO, que hace uso de tablas .DBF y para poder hacer la conceccion emplee el ODBC con un nombre conección X en "DSN de usuario". Mi pregunta es :es posible realizar la conección ODBC automática, es decir sin la necesidad de realizar la conección ODBC en capa PC que empleara el sistemas. Y de ser así serian tan amables de enviar un ejemplo al correo sgt:
[email protected]

1 Respuesta

Respuesta
1
Este es un codigo que saque por ahi. Funciona Bien...
---Comienzo del codigo---
'Task: This code snippet creates a DSN at runtime. The parameters are read through an INI file.
'Declarations
Option Explicit
'Constant Declaration
Private Const ODBC_ADD_DSN = 1 ' Add data source
Private Const ODBC_ADD_SYS_DSN = 4 'Add System DSN
Private Const ODBC_CONFIG_DSN = 2 ' Configure (edit) data source
Private Const ODBC_REMOVE_DSN = 3 ' Remove data source
Private Const vbAPINull As Long = 0 ' NULL Pointer
'Function Declare
#If Win32 Then
Private Declare Function SQLConfigDataSource Lib "ODBCCP32.DLL" _
(ByVal hwndParent As Long, ByVal fRequest As Long, _
ByVal lpszDriver As String, ByVal lpszAttributes As String) _
As Long
#Else
Private Declare Function SQLConfigDataSource Lib "ODBCINST.DLL" _
(ByVal hwndParent As Integer, ByVal fRequest As Integer, ByVal _
lpszDriver As String, ByVal lpszAttributes As String) As Integer
#End If
Private Declare Function SQLGetInstalledDriver Lib "ODBCCP32.DLL" _
(ByVal lDrvList As String, ByVal lpszDriver As Long, ByVal lpszAttributes As Long) As Long
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim dbPath As String
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
'Code:
Private Sub getINIDBPath()
Dim iniPath As String
dbPath = String(255, " ")
iniPath = App.Path & "DSN.ini"
Call GetPrivateProfileString("DSN", "ServerPath", "Default", dbPath, 255, iniPath)
createDSN
End Sub
Private Sub createDSN()
readINI (App.Path & "DSN.INI")
#If Win32 Then
Dim intRet As Long
#Else
Dim intRet As Integer
#End If
Dim strDriver As String
Dim strAttributes As String
strDriver = "SQL Server"
sDBPath = ""
sDBPath = "DSN=dScanTemp;" '& Chr$(0)
sDBPath = sDBPath & "DRIVER={SQL Server};"
sDBPath = sDBPath & "SERVER={COMP163};" '& Chr$(0)
sDBPath = sDBPath & "DATABASE=Scan;"
sDBPath = sDBPath & "UID=sa;"
strAttributes = sDBPath
intRet = SQLConfigDataSource(vbAPINull, ODBC_ADD_DSN, strDriver, strAttributes)
If intRet Then
MsgBox "DSN Created "
Else
MsgBox "DSN Creation Failed please Check ... ", vbCritical, "DSN Creation"
End If
End Sub
Private Sub Form_Load()
getINIDBPath
End Sub
---Fin del codigo---

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas