Sign in to follow this  
Followers 0
keyser94

Problem to connect to Oracle

6 posts in this topic

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Thanks a lot

I have look the registry and effectivly i have more than 20 entries

I have set the loop to 50 and it's now ok

Many thanks :D

Share this post


Link to post
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
Sign in to follow this  
Followers 0