Conexion à une base de données oracle

vingrid6 Messages postés 13 Date d'inscription lundi 29 novembre 2004 Statut Membre Dernière intervention 20 décembre 2004 - 8 déc. 2004 à 15:50
thierrydelepine Messages postés 521 Date d'inscription mardi 24 décembre 2002 Statut Membre Dernière intervention 11 septembre 2008 - 8 déc. 2004 à 22:21
Voilà ce que j'ai commencé à écrire pour me connecter à la base et quand je compile le programme ne rentre pas dans ma fonction
si quelqu'un a une idée celle ci est la bienvenue

'Ecriture d'une fonction permettant de se connecter à la base de donnée oracle
Option Explicit

Dim Initconnexion As Boolean
Private connexion As String
Private strErreur As String
Dim chaineConnexion As ADODB.Connection

Public Function InitConnection_Initialize() As Boolean
MsgBox "bonjour"
'on ouvre la connexion
On Error GoTo Badconnexion

connexion = "Provider=oraOLEDB.Oracle.1;" & _
"Password=carte;Persist Security Info=true;" & _
"User ID=carte;Data Source=carte"

MsgBox "début connexion"

Set chaineConnexion = New ADODB.Connection
With chaineConnexion
.ConnectionString = connexion
.CursorLocation = adUseClient
.Open
End With
MsgBox "connexion en cours"

DataEnvironnementTEST.CARTE.ConnexionString = chaineConnexion
MsgBox "connexion après data"

InitConnection_Initialize = True

Exit Function

Appel de la fonction dans sub form_load

Public Sub Form_Load()

MsgBox "bonjour"
Dim basemode As Boolean
Dim verification As Boolean

If basemode = 1 Then
MsgBox "on est en mode globale"
'on va se connecter à oracle
verification = InitConnection_Initialize()
Select Case verification
Case True
MsgBox "Connexion OK", vbExclamation, "Connexion"
Case False
MsgBox "Non Connecté", vbExclamation, "Erreur"
Exit Sub
Case Else
MsgBox "Erreur non conu", vbExclamation, "Erreur"
Exit Sub
End Select

Else: basemode = False

MsgBox "on est en mode local"
End If

End Sub

Badconnexion:

If strError = 3255 Then
MsgBox "Erreur à la connexion: " & _
"La Connexion à la base de données n'a pas pu s'établir"
End If

If strError = 3709 Then
MsgBox "Erreur à la connexion: " & _
"Il y a un Erreur dans le Reseau, c'est un erreur exterieur"
End If

InitConection_Initialize = False

End Function

1 réponse

thierrydelepine Messages postés 521 Date d'inscription mardi 24 décembre 2002 Statut Membre Dernière intervention 11 septembre 2008 6
8 déc. 2004 à 22:21
tu as peut etre oublié ca : basemode = True et en plus basemode est defini comme boolean donc if basemode=1 then ...
ca marche pas

et le form_load un peut mal placé

Option Explicit

Dim Initconnexion As Boolean
Private connexion As String
Private strErreur As String
Dim chaineConnexion As ADODB.Connection

Public Function InitConnection_Initialize() As Boolean
MsgBox "bonjour"
'on ouvre la connexion
On Error GoTo Badconnexion

connexion = "Provider=oraOLEDB.Oracle.1;" & _
"Password=carte;Persist Security Info=true;" & _
"User ID=carte;Data Source=carte"

MsgBox "début connexion"

Set chaineConnexion = New ADODB.Connection
With chaineConnexion
.ConnectionString = connexion
.CursorLocation = adUseClient
.Open
End With
MsgBox "connexion en cours"

DataEnvironnementTEST.CARTE.ConnexionString = chaineConnexion
MsgBox "connexion après data"

InitConnection_Initialize = True

Exit Function

Badconnexion:

If strError = 3255 Then
MsgBox "Erreur à la connexion: " & _
"La Connexion à la base de données n'a pas pu s'établir"
End If

If strError = 3709 Then
MsgBox "Erreur à la connexion: " & _
"Il y a un Erreur dans le Reseau, c'est un erreur exterieur"
End If

InitConection_Initialize = False

End Function

Sub Form_Load()

MsgBox "bonjour"
Dim basemode As Boolean
Dim verification As Boolean

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'il faut que basemode soit a True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
basemode = True
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If basemode = True Then
MsgBox "on est en mode globale"
'on va se connecter à oracle
verification = InitConnection_Initialize()
Select Case verification
Case True
MsgBox "Connexion OK", vbExclamation, "Connexion"
Case False
MsgBox "Non Connecté", vbExclamation, "Erreur"
Exit Sub
Case Else
MsgBox "Erreur non conu", vbExclamation, "Erreur"
Exit Sub
End Select

Else: basemode = False

MsgBox "on est en mode local"
End If

End Sub
0
Rejoignez-nous