1

私は現在、小型の古い VB6 アプリケーションを使用しています。

ここに私の問題があります: ユーザーがボタンをクリックすると、プログラムは Oracle データベースへの接続を開きます。これは、IDE から実行する場合、または Windows 95 または Windows 98 互換モードで .exe を実行する場合にうまく機能しますが、それ以外の場合はクラッシュします。別のワークステーションでも動作しますが、理由はわかりません (構成は異なりますが、それが何であるかはわかりません!)

ボタンが押されたときに呼び出されるコードは次のとおりです (互換性設定が設定されていない別のワークステーションで動作しますが、他の構成の違いがある可能性があります)。ほとんどのコードは接続に関連していませんが、完全を期すためにそのままにしておきます。

Private Sub Form_Load()
'
'   Loads the list of printers (as defined in a table of the SQL DB)
'
    On Error GoTo error_handler

    '   icon
    Screen.MousePointer = vbHourglass


    'Dim conn As New adodb.Connection
    'Dim cmd As New adodb.Command
    'Dim rcs As New adodb.Recordset
    Dim conn As adodb.Connection
    Dim cmd As adodb.Command
    Dim rcs As adodb.Recordset

    Set conn = New adodb.Connection
    Set cmd = New adodb.Command
    Set rcs = New adodb.Recordset

    'Dim fs As New FileSystemObject
    Dim fs As FileSystemObject
    Set fs = New FileSystemObject
    Dim fic As File
    Dim texte As textStream
    Dim req As String


    Dim i As Integer
    Dim chem As Variant

    Dim buffer As String
    Dim retstring As String
    Dim rc As Long

    If fs.FileExists(Appli_Rep & "Queries\System\printers_list.txt") Then
        Set fic = fs.GetFile(Appli_Rep & "Queries\System\printers_list.txt")
        Set texte = fic.OpenAsTextStream(ForReading)
    End If


    '
    '   Reads connection string
    '
    buffer = String(145, " ")
    rc = GetPrivateProfileString("Requete", "DRIVER", "1", buffer, Len(buffer) - 1, Appli_Rep & "suivi__.ini")
    DoEvents
    retstring = Left(buffer, InStr(buffer, Chr(0)) - 1)

    '
    '   Gets the PATH environment variable
    '   So that we know where to find tnsname.ora
    '
    i = 0
    chem = Split(Environ("TNS_ADMIN"), ";")
    Do
        If Len(Dir(chem(i) & "\Tnsnames.ora")) <> 0 Then
            ChDrive chem(i)
            ChDir chem(i)
            Exit Do
        End If
        i = i + 1
        DoEvents
    Loop Until i > UBound(chem)


    ' Opens a connection (no DSN)

    'Set conn = New adodb.Connection
    conn.ConnectionString = "uid=_uid;pwd=_pwd;DRIVER=" & retstring & ";server=__PROD;"
    'conn.ConnectionTimeout = 30
    conn.ConnectionTimeout = 3000    ' (no change)

    conn.Open   ' -2147467259 [Microsoft][ODBC driver for Oracle][Oracle]ORA-06413: Connexion non ouverte
        ' Connexion non ouverte = french for "connection is closed".

    Set cmd.ActiveConnection = conn

    cmd.CommandText = texte.ReadAll

    DoEvents

    Set texte = Nothing
    Set fic = Nothing
    Set fs = Nothing

    Set rcs = cmd.Execute

    DoEvents

    rcs.MoveFirst

    Do
        Me.cbo_Imprimantes.AddItem (rcs.Fields("IMPRIMANTE").Value)
        rcs.MoveNext
        DoEvents
    Loop Until rcs.EOF

    '   Close connections / free objects
    Set rcs = Nothing
    Set cmd = Nothing
    If conn.State = 1 Then
        conn.Close
    End If
    Set conn = Nothing

    '   icon back to normal
    Screen.MousePointer = vbDefault

    Exit Sub

error_handler:

    '   retour normal
    Screen.MousePointer = vbDefault

    If Err.Number <> 0 Then
        MsgBox Err.Number & " " & Err.Description, vbCritical + vbOKOnly, "Erreur !!!"
        MsgBox Err.Source
    End If

    On Error Resume Next
    '   Fermeture des objets
    Set rcs = Nothing
    Set cmd = Nothing
    Set conn = Nothing
    Set texte = Nothing
    Set fic = Nothing
    Set fs = Nothing



End Sub

「conn.Open」ステートメントでクラッシュします。接続文字列はどちらの場合も同じです (「retstring」が有効であることを確認するために、メッセージ ボックスに表示しました)。

御時間ありがとうございます。

4

0 に答える 0