Public Sub VBA_DB_Test()
Dim strConn As String, strSQL As String, conn As Object, rs As Object, col As Integer
Set conn = CreateObject("ADODB.Connection")
Set ds = CreateObject("ADODB.RecordSet")
'strConn = "Provider=SQLOLEDB;Server=dlsa7458mr.database.windows.net;Database=betadb;Uid=chris;Pwd=zxc123"
strConn = "Provider=SQLOLEDB;Server=CHRISTOPHER-PC\CHRISCHEN;Database=TSQL2012;Integrated Security=SSPI"
strSQL = "SELECT * FROM [HR].[Employees]"
conn.Open strConn
conn.CommandTimeout = 720
With ds
.Open strSQL, conn
For col = 0 To ds.Fields.Count - 1
Worksheets("sheet1").Range("A1").Offset(0, col).Value = ds.Fields(col).Name
Next
Worksheets("sheet1").Range("A1").Offset(1, 0).CopyFromRecordset ds
End With
Set ds = Nothing
conn.Close
Set conn = Nothing
End Sub
Public Sub Test()
Dim strConn As String, strSQL As String, conn As Object, rs As Object, col As Integer
Set conn = CreateObject("ADODB.Connection")
Set ds = CreateObject("ADODB.RecordSet")
strConn = "Provider=SQLOLEDB;Server=dlsv7567pmr.database.windows.net;Database=betadb;Uid=chris;Pwd=zxc123!"
strSQL = "SELECT * FROM [S_ameury].[Users]"
conn.Open strConn
conn.CommandTimeout = 720
With ds
.Open strSQL, conn
For col = 0 To ds.Fields.Count - 1
Worksheets("sheet1").Range("A1").Offset(0, col).Value = ds.Fields(col).Name
Next
Worksheets("sheet1").Range("A1").Offset(1, 0).CopyFromRecordset ds
End With
Set ds = Nothing
conn.Close
Set conn = Nothing
End Sub
Public Sub VBA_DB_Test()Dim strConn As String, strSQL As String, conn As Object, rs As Object, col As Integer Set conn = CreateObject("ADODB.Connection") Set ds = CreateObject("ADODB.RecordSet")