Hello all,
I found what I thought was a working SQL solution, but I am still having errors. I get run time error saying server does not exist or access denied.
I am positive on the Password, User, and IP, but perhaps not as sure about the 'database'
Any help would be greatly appreciated.
I found what I thought was a working SQL solution, but I am still having errors. I get run time error saying server does not exist or access denied.
VBA Code:
Sub sqlmaybe()
'Initializes variables
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String
Dim StrQuery As String
'Setup the connection string for accessing MS SQL database
'Make sure to change:
'1: PASSWORD
'2: USERNAME
'3: REMOTE_IP_ADDRESS
'4: DATABASE
ConnectionString = "Provider=SQLOLEDB.1;Password=7*.8G9QH21;Persist Security Info=True;User ID=dabc_student;Data Source=142.93.121.174;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=postgres"
'Opens connection to the database
cnn.Open ConnectionString
'Timeout error in seconds for executing the entire query; this will run for 15 minutes before VBA timesout, but your database might timeout before this value
cnn.CommandTimeout = 900
'This is your actual MS SQL query that you need to run; you should check this query first using a more robust SQL editor (such as HeidiSQL) to ensure your query is valid
StrQuery = "SELECT * FROM public.film"
'Performs the actual query
rst.Open StrQuery, cnn
'Dumps all the results from the StrQuery into cell A2 of the first sheet in the active workbook
Sheets(1).Range("A2").CopyFromRecordset rst
End Sub
I am positive on the Password, User, and IP, but perhaps not as sure about the 'database'
Any help would be greatly appreciated.