Jump to content

Problem to connect to Oracle


keyser94
 Share

Recommended Posts

Hi all,

I make a script to connect to oracle bdd

#include <GUIConstants.au3>

Dim $oMyError

; Initializes COM handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$ado = ObjCreate( "ADODB.Connection" )    ; Create a COM ADODB Object  with the Beta version

With $ado
    .ConnectionString =("Driver={Microsoft ODBC for Oracle};Server=SERVER;Uid=LOGIN;Pwd=PASSWORD;")
    .Open
EndWith

$adors = ObjCreate( "ADODB.RecordSet" )    ; Create a Record Set to handles SQL Records

With $adors
        .ActiveConnection = $ado
        ;.CursorLocation = "adUseClient"
        ;.LockType = "adLockReadOnly" ; Set ODBC connection read only

        .Source = "select count(*) from images_produit_coloris"
        .Open
EndWith

My code works on my own computer.

But some others users of our network have a french drivers of Oracle

In fact to uses the script, i should use {Microsoft ODBC pour Oracle} instead "for"

So, is there a way to detect in the script which version of drivers (language) ?

So i will use one or the other line.

If not, is there a way to change {Microsoft ODBC pour Oracle} in {Microsoft ODBC for Oracle} on Windows Xp computer ?

Thanks

Regards

Keyser

Link to comment
Share on other sites

You could try a connection with the English version, check the return code and if there is an error try the French version.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hi,

not verified, because i haven't had any frech MS Oracle Driver installed and, of course, you can install an english driver on french system:

MsgBox (0,"", _getOdbcDataSource ())

; searching for MS ODBC Oracle english or french
; if found return ODBC source string
; if not found returns 0
Func _getOdbcDataSource ()
    Dim $arODBC [21]
    For $i= 1 to 20 ; Max 20 ODBC DRIVERS
         $var = RegEnumKey("HKLM\Software\ODBC\ODBCINST.INI", $i)
         If @error <> 0 then ExitLoop
         $arODBC [$i] = $var
    Next
    For $i = 1 To UBound ($arODBC) - 1
        If $arODBC [$i] = "" Then ExitLoop
        If StringInStr ($arODBC [$i], "Microsoft ODBC for Oracle") or StringInStr ($arODBC [$i], "Microsoft ODBC pour Oracle") Then
            Return $arODBC [$i]
        Else
            ContinueLoop
        EndIf
    Next
    Return 0
EndFunc

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi

Frist, thanks for your answer

I have tried your code with adding this

$driver_orcl = _getOdbcDataSource () 
With $ado     
  .ConnectionString =("Driver={" & driver_orcl & "};Server=SERVER;Uid=LOGIN;Pwd=PASSWORD;")     
  .Open 
EndWith

But it doesn't work

$driver_orcl always return 0

Your function seems to be good and stop well when it find the driver.

But it doesn't return which driver have been found

Link to comment
Share on other sites

Hi

Frist, thanks for your answer

I have tried your code with adding this

$driver_orcl = _getOdbcDataSource () 
With $ado     
  .ConnectionString =("Driver={" & driver_orcl & "};Server=SERVER;Uid=LOGIN;Pwd=PASSWORD;")     
  .Open 
EndWith

But it doesn't work

$driver_orcl always return 0

Your function seems to be good and stop well when it find the driver.

But it doesn't return which driver have been found

Hi,

so we have to do some debugging:

Return 0 means the requested keys aren't found.

1) You may have a 64 Bit Windows -> change HKLM to HKLM64

2) Just start regedit and have a look a the registry hive if the drivers are listed. They may are written in another way.

3) maybe there are listed more then 20 ODBC drivers ->

change in function _getODBCSource: Dim $arodbc [51] and in 1st for loop for $i = 1 to 50

If you can't solve problem next step:

1) Add #include <array.au3> at the include section of the script.

2) Add in function getODBCDataSource _ArrayDisplay ($arodbc) between the 2 for loops.

You should identify where is the problem and if the questioned ODBC drivers are listed.

You may post result of the arraydisplay.

;-))

Stefan

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...