I am trying to avoid a timeout situation happening. At present the script runs 100% on the test environment, but everything is running local. Therefore now installed on the live environment, it does take a little longer. However it would appear VB timeout default is set to 30 secs. However not being 100% familiar with VB unlike with SQL, then I am unsure on the code to set it. Current code is as follows:
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim dateRows As Variant
Dim i As Integer
Dim today As Date
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
strFile = Workbooks(1).FullName
strCon = "Provider=SQLOLEDB.1; Data Source=ABC;Initial catalog=ABC;Integrated Security=ABC;"
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
range1 = Sheets("Line data ( Do not alter )").Range("AA9")
cn.Open strCon
strSQL = "Select "order by userid, appointmentdate "
rs.Open strSQL, cn
Sheets("Line data ( Do not alter )").Range("AA9").CopyFromRecordset rs
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
I found code which states comm.CommandTimeout=10, but unsure where to put it..
Any help appreciated.
cn.CommandTimeout=10(or whatever you want to set timeout time to) sincecnis the variable for your connection object and theCommandTimeoutis a property of this object. Since you are using early binding, you can see all the properties of the Connection object by typing.aftercn.