Bonjour,
J'ai récupéré une requête pour lire depuis une macro excel une base sql qui fonctionne sauf que le time out de 30 secondes coince pour certaines extractions.
J'aimerais l'étendre, mais ne sais pas du tout comment faire.

Je ne sais pas comment gérer une commande de type time out.

Voici le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 
Sub GetDataFromADO()
    Cells.Select
    Range("b2:k65536").Select
    Selection.ClearContents
 
    'Declare variables'
        Dim objMyConn As ADODB.Connection
        Dim objMyCmd As ADODB.Command
        Dim objMyCmd2 As ADODB.Command
        Dim objMyRecordset As ADODB.Recordset
 
        Set objMyConn = New ADODB.Connection
        Set objMyCmd = New ADODB.Command
        Set objMyRecordset = New ADODB.Recordset
 
' C'est là que je ne sais pas comment syntaxer !!!!!!!
Set cmd = CreateObject("ADODB.Command")
Set cmd.CommandTimeout = 120
 
' ici la requête qui fonctionne
'Open Connection'
        objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=*****;Initial Catalogue=******;User ID=*****;Password=***;"
 
        objMyConn.Open
        Set objMyCmd.ActiveConnection = objMyConn
        objMyCmd.CommandText = "SELECT container.Container, Product.ProductNo, TT_Prod.Medium, Z_LOT_NO_CHARACTERISTIC.string02, APR_Inventory.LotNo, Container.Warehouse, APR_Inventory.Location, TT_Comment.Extended" & _
        " FROM [***].[dbo].[Inventory_Container]" & _
        " INNER JOIN [***].[dbo].[Container] ON container.container = inventory_container.container" & _
        " INNER JOIN [***].[dbo].[inventory] ON ID = Inventory_container.inventoryID " & _
        " INNER JOIN [***].[dbo].[APR_Inventory] ON APR_Inventory.InventoryId = Inventory.ID  " & _
        " INNER JOIN [***].[dbo].[LOT_NO] ON [***].[dbo].[LOT_NO].[LotNo] = APR_Inventory.LotNo" & _
        " INNER JOIN [***].[dbo].[Z_LOT_NO_CHARACTERISTIC] ON [flexnet].[dbo].[Z_LOT_NO_CHARACTERISTIC].[LotNo] = APR_Inventory.LotNo" & _
        " INNER JOIN [***].[dbo].[PRODUCT] ON PRODUCT.ID = [flexnet].[dbo].[inventory].ProductID" & _
        " INNER JOIN [***].[dbo].[TEXT_TRANSLATION] AS TT_Prod ON TT_Prod.TextID = PRODUCT.TextID AND TT_Prod.LanguageID = '1036'" & _
        " INNER JOIN [***].[dbo].[TEXT_TRANSLATION] AS TT_Comment ON TT_Comment.TextID = LOT_NO.TextID AND TT_Comment.LanguageID = '1036'" & _
        " WHERE Container.Container like '" + Worksheets("ProtectedSheet").Cells(1, 1).Value + "%'"
    'Open Recordset'
        Set objMyRecordset.Source = objMyCmd
        objMyRecordset.Open
 
    Range("B2").Select
    ActiveSheet.Range("B2").CopyFromRecordset objMyRecordset
Merci pour votre aide
Denis