• Martes 7 de Mayo de 2024, 21:03

Autor Tema:  Cambiar De Base De Sql Server A Mi Antojo  (Leído 1181 veces)

Gallagher

  • Miembro activo
  • **
  • Mensajes: 51
    • Ver Perfil
    • http://www.desvelat.com.ar
Cambiar De Base De Sql Server A Mi Antojo
« en: Martes 27 de Julio de 2004, 22:27 »
0
Como puedo hacer para concetarme  al servidor De SQL SERVER , sin usar ODBC directo a una BASe y poder crear un MENU, donde se puedea elegir uqe Base utilizar y de acuerdo a ella, usar un ADO vinculandola??

Shiquilla

  • Miembro MUY activo
  • ***
  • Mensajes: 188
  • Nacionalidad: es
    • Ver Perfil
    • http://www.songesoft.com
Re: Cambiar De Base De Sql Server A Mi Antojo
« Respuesta #1 en: Miércoles 28 de Julio de 2004, 19:03 »
0
Para sacar la lista de servidores, conectar al servidor y sacar el listado de BBDD:

Código: Text
  1.  
  2. Public CONN As New ADODB.Connection
  3.  
  4. Private Sub ObtenerListadoServidores()
  5.     Dim ServidoresSQL As SQLDMO.Application
  6.     Dim ListaServers As NameList
  7.     Dim i As Integer
  8.     
  9.     Set ServidoresSQL = New SQLDMO.Application
  10.     Set ListaServers = ServidoresSQL.ListAvailableSQLServers
  11.  
  12.     For i = 1 To ListaServers.Count
  13.         Servidor_SQL.AddItem ListaServers.Item(i)
  14.     Next
  15.     
  16.     Servidor_SQL.ListIndex = 0
  17.     Set ListaServers = Nothing
  18. End Sub
  19.  
  20.  
  21. Private Sub Conectar_SQL()
  22.     On Error GoTo error_Conexion
  23.         Set CONN = Nothing
  24.         CONN.Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=" & Servidor_SQL)
  25.         Databases
  26.     Exit Sub
  27. error_Conexion:
  28.     If Err.Number = -2147217843 Then
  29.         MsgBox "El usuario no existe o no tiene una conexión de confianza. Descripción: " & Err.Description, vbCritical
  30.     Else
  31.         MsgBox Err.Number & ". " & Err.Description
  32.     End If
  33. End Sub
  34.  
  35. Private Sub Databases()
  36.     Dim rs_BBDD As ADODB.Recordset
  37.     BBDD.Clear
  38.     Set rs_BBDD = New ADODB.Recordset
  39.     Set rs_BBDD = CONN.Execute("sp_databases")
  40.     If Not rs_BBDD.EOF Then
  41.      Do Until rs_BBDD.EOF
  42.         BBDD.AddItem (rs_BBDD.Fields("Database_Name"))
  43.         rs_BBDD.MoveNext
  44.      Loop
  45.      rs_BBDD.Close
  46.      BBDD.Enabled = True
  47.     End If
  48.     Set rs_BBDD = Nothing
  49.     BBDD.ListIndex = 0
  50.     BBDD.Enabled = True
  51. End Sub
  52.  
  53. Private Sub BBDD_DblClick()
  54.    CONN.Close
  55.    Set CONN = Nothing
  56.    CONN.Open ("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=" & Servidor_SQL & "Initial Catalog=" & BBDD.Text)
  57. End Sub
  58.  
  59.  

Referencias necesarias:
    Microsoft SQLDMO Object Library
    Microsoft ActiveX Data Object 2.7 Library (en mi caso)</li>
Espero que te sirva de ayuda,

Saludos.
« §hÿqµïllæ »