Click to See Complete Forum and Search --> : list all the databases


Karina Gámez
August 21st, 2001, 06:53 PM
Can someone give me the code generate a list of the names of all the databases from the server that i choose...???

I already list all of the sql server.. but now i need to know if i can list the databases...

Thanks a lot!

Karina Gámez
September 21st, 2001, 06:54 PM
solution: NetEnum

sorry.. this one.. list all available servers--- not databases..



private Sub Form_Load()

Dim pszTemp as string, pszServer as string, pszDomain as string
Dim nLevel as Long, i as Long, BufPtr as Long, TempBufPtr as Long
Dim nPrefMaxLen as Long, nEntriesRead as Long, nTotalEntries as Long
Dim nServerType as Long, nResumeHandle as Long, nRes as Long
Dim ServerInfo as SERVER_INFO_101

me.Left = Screen.Width / 2 - me.Width / 2
me.Top = Screen.Height / 2 - me.Height / 2

' Definiciones de los parámetros
nLevel = 101
BufPtr = 0
nPrefMaxLen = &HFFFFFFFF
nEntriesRead = 0
nTotalEntries = 0
nServerType = SV_TYPE_SQLSERVER ' Se define que tipo de servidores se desea cargar
nResumeHandle = 0

Do
nRes = NetServerEnum(pszServer, nLevel, BufPtr, _
nPrefMaxLen, nEntriesRead, nTotalEntries, _
nServerType, pszDomain, nResumeHandle)
If ((nRes = ERROR_SUCCESS) Or (nRes = ERROR_MORE_DATA)) And _
(nEntriesRead > 0) then
TempBufPtr = BufPtr
for i = 1 to nEntriesRead
RtlMoveMemory ServerInfo, TempBufPtr, SIZE_SI_101
Debug.print PointerToString(ServerInfo.lpszServerName)
TempBufPtr = TempBufPtr + SIZE_SI_101
next i
lstservers.ListIndex = 0
else
MsgBox "NetServerEnum failed: " & nRes
End If
NetApiBufferFree (BufPtr)
Loop While nEntriesRead < nTotalEntries



End Sub
private Function PointerToString(lpszString as Long) as string
Dim lpszStr1 as string, lpszStr2 as string, nRes as Long

lpszStr1 = string(1000, "*")
nRes = lstrcpyW(lpszStr1, lpszString)
lpszStr2 = (StrConv(lpszStr1, vbFromUnicode))
PointerToString = Left(lpszStr2, InStr(lpszStr2, Chr$(0)) - 1)
lstservers.AddItem (PointerToString)

End Function

Karina Gámez
September 21st, 2001, 06:56 PM
and if u want to list the databases of one servers---


private Sub cboserver_Click() ' Al momento de presionar al combo, este realiza una conexión temporal para listar las bd
Dim sqlserver as SQLDMO.sqlserver

set sqlserver = new SQLDMO.sqlserver 'Instanciamos la variable

sqlserver.LoginSecure = true
sqlserver.Connect cboserver.Text ' solo conectamos para enumerar las bases de datos
RefreshDatabaseList

sqlserver.Disconnect 'desconectamos
set sqlserver = nothing 'liberamos memoria
End Sub