Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Set cnSQL = New ADODB.Connection 'cnSQL.Open "ODBC;DRIVER=SQL Server; Authentication = ActiveDirectoryInteractive; Database=XXXXX; Data Source=XXXX.database.windows.net"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

This should give you what you need.

You'll have to download the ODBC Driver 17 for SQL Server and depending on your connection type you can update Authentication option

Sub AdoOdbcExample()    
    Dim con As Object    
    Set con = CreateObject("ADODB.Connection") 
    con.Open _
            "Driver={ODBC Driver 17 for SQL Server};" & _
            "Server=tcp:yourserver.database.windows.net,1433;" & _
            "Database=yourdb;" & _
            "Trusted_Connection=no;" & _
            "Authentication=ActiveDirectoryInteractive;" & _
            "UID=youremail;"
    con.Execute "UPDATE Clients SET FirstName='Gord' WHERE ID=5;"    
    con.Close    
    Set con = Nothing   
    'Authentication=ActiveDirectoryIntegrated
    'Authentication=ActiveDirectoryInteractive
    'ActiveDirectoryPassword  

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...