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
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