none
Conectar no Banco de Dados Oracle Prime RRS feed

Respostas

  • Pamela, boa tarde.

    A Microsoft disponibiliza esse código de conexão com bancos de dados oracle.

    ' Visual Basic Public Sub ConnectToOracle() Dim conn As New OracleClient.OracleConnection() ' TODO: Modify the connection string and include any ' additional required properties for your database. conn.ConnectionString = & _ "Data Source=<oracle data source name>;Integrated Security=yes" Try conn.Open() ' Insert code to process data. Catch ex As Exception MessageBox.Show("Failed to connect to data source") Finally conn.Close() End Try End Sub // C# public void ConnectToOracle() { OracleClient.OracleConnection conn = new OracleClient.OracleConnection (); // TODO: Modify the connection string and include any // additional required properties for your database. conn.ConnectionString = "Data Source=" + "<oracle data source name>;Integrated Security=yes"; try { conn.Open(); // Insert code to process data. } catch (Exception ex) { MessageBox.Show("Failed to connect to data source"); } finally { conn.Close(); } }

    Referência:

    http://msdn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx

    Espero ter ajudado.


    Hezequias Vasconcelos

    sexta-feira, 14 de setembro de 2012 15:49
    Moderador
  • Para um código VBA:

    Sub GetData()
    
        Dim SQL_String As String
        Dim dbConnectStr As String
        Set con = New ADODB.Connection
        Set recset = New ADODB.Recordset
        Dim recordCount As Long
        dbConnectStr = "Provider=msdaora;Data Source=" & "Oracle_Database_Name;"
        dbConnectStr = dbConnectStr & "User Id=userId" & "; Password=" & "password"
        'The statement above has been commented out. I use the statement below to prompt the user for the userId and password - which is what I prefer!
    
        con.ConnectionString = dbConnectStr
        con.Properties("Prompt") = adPromptAlways
        con.Open dbConnectStr    'ConnectionString
    
        'This is an example SQL code that you might want to run
        'Select * From MyTable
    
        'SQL_String = "Select count(*) from adm_user"
        recset.Open SQL_String, con
        recset.MoveLast
        recordCount = recset.recordCount
        recset.MoveFirst
        Do While Not recset.EOF = True
            'Have a loop here to go through all the fields
            recset.MoveNext
        Loop
        recset.Close
    End Sub

    Fonte: http://www.vbaexpress.com/forum/showthread.php?t=40986

    Para a cadeia de conexão, veja: http://www.connectionstrings.com/oracle

    Confira também: http://www.learnexcelmacro.com/2011/11/oracle-connection-string-in-vba/


    Felipe Costa Gualberto - http://www.ambienteoffice.com.br

    sexta-feira, 14 de setembro de 2012 20:55
    Moderador

Todas as Respostas

  • Pamela, boa tarde.

    A Microsoft disponibiliza esse código de conexão com bancos de dados oracle.

    ' Visual Basic Public Sub ConnectToOracle() Dim conn As New OracleClient.OracleConnection() ' TODO: Modify the connection string and include any ' additional required properties for your database. conn.ConnectionString = & _ "Data Source=<oracle data source name>;Integrated Security=yes" Try conn.Open() ' Insert code to process data. Catch ex As Exception MessageBox.Show("Failed to connect to data source") Finally conn.Close() End Try End Sub // C# public void ConnectToOracle() { OracleClient.OracleConnection conn = new OracleClient.OracleConnection (); // TODO: Modify the connection string and include any // additional required properties for your database. conn.ConnectionString = "Data Source=" + "<oracle data source name>;Integrated Security=yes"; try { conn.Open(); // Insert code to process data. } catch (Exception ex) { MessageBox.Show("Failed to connect to data source"); } finally { conn.Close(); } }

    Referência:

    http://msdn.microsoft.com/en-us/library/xexk8kx3(v=vs.71).aspx

    Espero ter ajudado.


    Hezequias Vasconcelos

    sexta-feira, 14 de setembro de 2012 15:49
    Moderador
  • Para um código VBA:

    Sub GetData()
    
        Dim SQL_String As String
        Dim dbConnectStr As String
        Set con = New ADODB.Connection
        Set recset = New ADODB.Recordset
        Dim recordCount As Long
        dbConnectStr = "Provider=msdaora;Data Source=" & "Oracle_Database_Name;"
        dbConnectStr = dbConnectStr & "User Id=userId" & "; Password=" & "password"
        'The statement above has been commented out. I use the statement below to prompt the user for the userId and password - which is what I prefer!
    
        con.ConnectionString = dbConnectStr
        con.Properties("Prompt") = adPromptAlways
        con.Open dbConnectStr    'ConnectionString
    
        'This is an example SQL code that you might want to run
        'Select * From MyTable
    
        'SQL_String = "Select count(*) from adm_user"
        recset.Open SQL_String, con
        recset.MoveLast
        recordCount = recset.recordCount
        recset.MoveFirst
        Do While Not recset.EOF = True
            'Have a loop here to go through all the fields
            recset.MoveNext
        Loop
        recset.Close
    End Sub

    Fonte: http://www.vbaexpress.com/forum/showthread.php?t=40986

    Para a cadeia de conexão, veja: http://www.connectionstrings.com/oracle

    Confira também: http://www.learnexcelmacro.com/2011/11/oracle-connection-string-in-vba/


    Felipe Costa Gualberto - http://www.ambienteoffice.com.br

    sexta-feira, 14 de setembro de 2012 20:55
    Moderador