RE:Origen de base de datos via código.
paso 1.
crea un objeto datawindow con los siguientes campos
dbms
profile
provider
database
servername
logid
logpass
autocommit
dbparm
paso 2
// crea una funcion algo asi
of_SetRegisterODBC(string as_section, string as_key,string as_value) return (none)
String ls_regkey
ls_regkey = "HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\"
RegistrySet(ls_regkey + as_section, as_key, as_value)
ls_regkey = "HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources"
RegistrySet(ls_regkey , as_section ,"SQL Server")
paso 3
// script en un command button
string ls_profile,ls_provider
Transaction ltr_connection
DataWindow idw_handle
idw_handle = dw_1
idw_handle.AcceptText()
long ll_pos
// creo la entrada odbc
ls_profile = trim(idw_handle.getitemstring(1,"profile"))
if trim(ls_profile) = "" then
MessageBox("Error","Ingrese el Nombre del Perfil de conexción",StopSign!)
idw_handle.setcolumn("profile") ; idw_handle.setfocus() ; return -1
end if
ll_pos = pos(ls_profile,' ')
if ll_pos > 0 then
MessageBox("Error","El perfil no permite espacios en blanco",StopSign!)
idw_handle.setcolumn("profile") ; idw_handle.setfocus() ; return -1
end if
ls_provider = idw_handle.getitemstring(ll_row,"Provider")
// registro el odbc
of_setregisterodbc( ls_profile,"DataBase",idw_handle.getitemstring(ll_row,"DataBase"))
of_setregisterodbc(ls_profile,"Description","")
of_setregisterodbc( ls_profile,"Driver","C:\WINDOWS\system32\SQLSRV32.dll")
of_setregisterodbc( ls_profile,"LastUser", idw_handle.getitemstring( ll_row,"LogId"))
of_setregisterodbc( ls_profile,"Server", idw_handle.getitemstring( ll_row,"ServerName"))
// aqui compruebas si la conexion fue satisfactoria
ls_autocommit = lower(idw_handle.getitemstring(ll_row,"AutoCommit"))
if ls_autocommit = 'true' or ls_autocommit = 'on' or ls_autocommit = '1' then
ib_autocommit = True
elseif ls_autocommit = 'false' or ls_autocommit = 'off' or ls_autocommit = '0' then
ib_autocommit = False
End if
ltr_connection = Create Transaction
ltr_connection.DBMS = idw_handle.getitemstring( ll_row, "DBMS")
ltr_connection.DataBase = idw_handle.getitemstring(ll_row,"DataBase")
ltr_connection.ServerName= idw_handle.getitemstring( ll_row,"ServerName")
ltr_connection.LogId =idw_handle.getitemstring( ll_row,"LogId")
ltr_connection.LogPass = idw_handle.getitemstring( ll_row,"LogPass")
ltr_connection.DBParm = idw_handle.Getitemstring( ll_row,"DBParm")
Connect Using ltr_connection;
if ltr_connection.SQLCode <> 0 then
MessageBox("Error", &
"Error al conectar con la base de datos~r Verifique los parámetros de ingreso",StopSign!)
Destroy ltr_connection;
Return -1
End If
// si todo ok
creas tu conexion ya sea en archivo ini o clave de registro o donde tu quieras con el fin de obtener estos datos y establecer la conexion
los providers lo encuentras en
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Providers"
puedes crear una funcion para obtener en un dddw todo los providers de sql
es script es parte de lo que quieres. no puedo pasarte los objetos porque están super heredados.
coméntalo si todo va ok.