Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default shorten connection time <<Macro Tweak needed

Hello -

I have the following code which opens up a SQL connection and then
dumps the data into Excel. Everything works fine, except that if
there is no ODBC connection found/made after 10 seconds, I just want
the "wating period" to end.

It seems that changing the ConnectionTimeout and CommandTimeout to a
lower value doesn't seem to do the job. No matter what I change these
values to, the process time for this macro is still 60 seconds.


Private Sub Workbook_Open()
Dim cnn1 As ADODB.Connection
Dim runspcmd As ADODB.Command
Dim x As Integer

Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "Provider=sqloledb;Data
Source=00.00.000.000;Initial Catalog=xxdatadb;User Id=xx;Password=xx;"
cnn1.ConnectionTimeout = 60
' cnn1.Open
On Error Resume Next
cnn1.Open
On Error GoTo 0


If cnn1.State < adStateOpen Then
Debug.Print "Connection failed!"
Exit Sub
End If

Set runspcmd = New ADODB.Command
runspcmd.ActiveConnection = cnn1
runspcmd.CommandTimeout = 60

x = 0

Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient

runspcmd.CommandText = "select vendor_name, vendor_code from " & _
" vendor order by
vendor_name "
rs.Open runspcmd

If Not rs.EOF Then
Me.Worksheets.Item(2).Range("A1").CopyFromRecordse t rs
End If

rs.Close
cnn1.Close
End Sub


Thanks for any insight someone can provide!
Dan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
clear option buttons **MACRO TWEAK** Dan Excel Programming 4 February 19th 07 05:34 PM
Newby Needs minor tweak on this VBA Macro code for Excel zulfer7 Excel Programming 1 May 21st 06 05:30 AM
Can someone please tweak my Macro? Wibs Excel Discussion (Misc queries) 3 December 15th 05 05:10 PM
Macro needed; save a file two (or more places) at the same time Sigurd Excel Programming 3 March 2nd 04 11:20 PM
Help needed coding a macro to adjust the source of information each time it is run lbauckman Excel Programming 1 November 4th 03 08:13 AM


All times are GMT +1. The time now is 04:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"