Asignar BD a un ODBC mediante código VB6
Mi problema creo yo es algo sencillo de resolver ya que tengo la mayor parte de código hecho sin embargo no puedo dar con la solución de la parte final.
Mi código consta que con un evento clic de botón o con el load de un formulario me cree un nuevo ODBC hasta aquí sin problemas, el problema entra en que no se como asiganrle la BD a la que quiero hacer referencia.
Aqui esta micodigo:
NOTA: mi BD es (validación.mdb) y esta en la ruta de red Y:\Control_usuarios\
Código:
Option Explicit
Private Const REG_SZ = 1 'Constant for a string variable type.
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias _
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal _
cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Sub Command1_Click()
Dim DataSourceName As String
Dim DatabaseName As String
Dim Description As String
Dim DriverPath As String
Dim DriverName As String
Dim LastUser As String
Dim Regional As String
Dim Server As String
Dim lResult As Long
Dim hKeyHandle As Long
'Declara las caracteristicas del DNS
DataSourceName = "Cyber"
DatabaseName = "validacion.mdb"
Description = "Base de datos cyber aramar@"
DriverPath = "D:\Program Files\Microsoft Visual Studio\Vfp98\Distrib.src\System\"
LastUser = ""
Server = ""
DriverName = "ODBCJT32.DLL"
'Crea HKEY en el registro
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & _
DataSourceName, hKeyHandle)
'Establece los valores en el registro del DNS
lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, _
ByVal DatabaseName, Len(DatabaseName))
lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, _
ByVal Description, Len(Description))
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
ByVal DriverPath, Len(DriverPath))
lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, REG_SZ, _
ByVal LastUser, Len(LastUser))
lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, _
ByVal Server, Len(Server))
'Se cierra el HKEY del nuevo DNS.
lResult = RegCloseKey(hKeyHandle)
'Abre el administrador de ODBC para cargar el nuevo ODBC.
'Establece su valores.
'Cierra el Hkey.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, _
ByVal DriverName, Len(DriverName))
lResult = RegCloseKey(hKeyHandle)
End Sub
Muchas gracias por su ayuda estaré al pendiente.
Mi código consta que con un evento clic de botón o con el load de un formulario me cree un nuevo ODBC hasta aquí sin problemas, el problema entra en que no se como asiganrle la BD a la que quiero hacer referencia.
Aqui esta micodigo:
NOTA: mi BD es (validación.mdb) y esta en la ruta de red Y:\Control_usuarios\
Código:
Option Explicit
Private Const REG_SZ = 1 'Constant for a string variable type.
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias _
"RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias _
"RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal _
cbData As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Sub Command1_Click()
Dim DataSourceName As String
Dim DatabaseName As String
Dim Description As String
Dim DriverPath As String
Dim DriverName As String
Dim LastUser As String
Dim Regional As String
Dim Server As String
Dim lResult As Long
Dim hKeyHandle As Long
'Declara las caracteristicas del DNS
DataSourceName = "Cyber"
DatabaseName = "validacion.mdb"
Description = "Base de datos cyber aramar@"
DriverPath = "D:\Program Files\Microsoft Visual Studio\Vfp98\Distrib.src\System\"
LastUser = ""
Server = ""
DriverName = "ODBCJT32.DLL"
'Crea HKEY en el registro
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\ODBC\ODBC.INI\" & _
DataSourceName, hKeyHandle)
'Establece los valores en el registro del DNS
lResult = RegSetValueEx(hKeyHandle, "Database", 0&, REG_SZ, _
ByVal DatabaseName, Len(DatabaseName))
lResult = RegSetValueEx(hKeyHandle, "Description", 0&, REG_SZ, _
ByVal Description, Len(Description))
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
ByVal DriverPath, Len(DriverPath))
lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, REG_SZ, _
ByVal LastUser, Len(LastUser))
lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, _
ByVal Server, Len(Server))
'Se cierra el HKEY del nuevo DNS.
lResult = RegCloseKey(hKeyHandle)
'Abre el administrador de ODBC para cargar el nuevo ODBC.
'Establece su valores.
'Cierra el Hkey.
lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, REG_SZ, _
ByVal DriverName, Len(DriverName))
lResult = RegCloseKey(hKeyHandle)
End Sub
Muchas gracias por su ayuda estaré al pendiente.
1 respuesta
Respuesta de Roberto Alvarado