PDA

View Full Version : Azure Connection via VB error



johnsummer
04-05-2020, 11:06 PM
​Sub SQL_Connection()


Dim con As ADODB.Connection 'to get connection
Dim rs As ADODB.Recordset ' to get record set
Dim query As String ' to get query
Set con = New ADODB.Connection ' to inistate connection
Set rs = New ADODB.Recordset ' to inisate record set ' rs= reocrd set




strCon = "Trusted_Connection=False;Encrypt=True; Data Source=servername.database.windows.net,1433; Initial Catalog=datbasename;Integrated Security=SSPI"
con.Open (strCon)
If con.State = adStateOpen Then
MsgBox "Your connected now!"
SQLStr = "SELECT TOP (10)*FROM xxxxxxxx"
rs.Open SQLStr, con, adOpenStatic
With Worksheets("sheet1").Range("a6:z500")
.ClearContents
.CopyFromRecordset rs
End With
Else
MsgBox "Sorry. you dont have access bud."
End If


rs.Close
Set rs = Nothing
con.Close
Set con = Nothing
End Sub

Jan Karel Pieterse
04-06-2020, 07:51 AM
What is your question?

paulked
04-06-2020, 02:43 PM
There is an error here:



MsgBox "Your connected now!"


should be



MsgBox "You're connected now!"


:whistle::whistle: