Vedere il nome delle tabelle via ODBC

di il
4 risposte

Vedere il nome delle tabelle via ODBC

Salve!

ho un database su un pc della rete.
dal pc della mia scrivania ho solo word ed excel

ho creato un collegamento odbc
e la connessione funziona

c'e' un modo di avere del codice VBA per vedere il nome delle tabelle?

Grazie

PFMarro

4 Risposte

  • Re: Vedere il nome delle tabelle via ODBC

    SQL Server 2005 or 2008:
    SELECT * FROM information_schema.tables
    Dovrebbe funzionare anche questa:
    SELECT sobjects.name
    FROM sysobjects sobjects
    WHERE sobjects.xtype = 'U'
    oppure questo:
    select * from sys.tables;
    Ovviamente devi eseguirle con delle queries di tipo PASSTROUGHT
  • Re: Vedere il nome delle tabelle via ODBC

    Grazie!

    in effetti con query Pass-through
    con l'interfaccia grafica della query
    selezionado
    SELECT * FROM information_schema.tables

    funziona

    il mio problema e' che sul mio client ho solo Excel e word.
    il collegamento ODBC e' corretto

    Come posso fare?
    mi consigli del codice al riguardo?
    ADO + odbc?

    Grazie
  • Re: Vedere il nome delle tabelle via ODBC

    Salve

    ho apportato alcune prove con vb6
    ' riferimenti:
    ' Microsoft ActiveX Data Objects 2.5 Library
    ' Microsoft Data Binding Collection VB 6.0 (SP4)

    CON VB6 FUNZIONA, CON EXCEL 2003 no


    Dim pfmStringSql_viaODBC As String



    pfmStringSql_viaODBC = "Provider=MSDASQL.1; " & _
    "PWD=xxxx; " & _
    "Trusted_Connection=no; " & _
    "Initial Catalog=xxxSID; " & _
    "Data Source=xxxSID_locale; " & _
    "Initial File Name=''; " & _
    "Server SPN=''"

    Dim cnConn As ADODB.Connection
    Dim cmdCommand As New ADODB.Command
    Dim rstRecordSet As New ADODB.Recordset

    Set cnConn = New ADODB.Connection

    cnConn.ConnectionString = pfmStringSql_viaODBC

    cnConn.CursorLocation = adUseClient
    cnConn.Open

    ' elenco tabelle
    With cmdCommand
    .ActiveConnection = cnConn
    ' .CommandText = "SELECT * FROM tabTestTable;"
    .CommandText = "SELECT * FROM information_schema.tables;"
    .CommandType = adCmdText
    End With

    With rstRecordSet
    .CursorType = adOpenStatic
    .CursorLocation = adUseClient
    .LockType = adLockOptimistic
    .Open cmdCommand
    End With

    MsgBox rstRecordSet.Fields(1).Name & " ----> " & rstRecordSet.Fields(1).Value
  • Re: Vedere il nome delle tabelle via ODBC

    A prescindere che puoi usare tranquillamente ADO, ma le Query PT non è che si fanno solo con ACCESS da QBE... la Q_PT la crei con DAO con il metodo CreateQueryDefs(....) e da li la crei in modo TEMP... e la esegui...

    Vedi tu.
Devi accedere o registrarti per scrivere nel forum
4 risposte