Vb et sql server 2000

bilalstar Messages postés 70 Date d'inscription dimanche 27 mars 2005 Statut Membre Dernière intervention 3 octobre 2005 - 17 mai 2005 à 23:34
nawakator Messages postés 51 Date d'inscription lundi 12 mai 2003 Statut Membre Dernière intervention 8 février 2011 - 18 mai 2005 à 11:21
bonjour,
quelqu'un pourra m'expliquer en bref cmt connecter ma base de donnes sql serever 2000 a mon application vb6.
merci d'avance.

1 réponse

nawakator Messages postés 51 Date d'inscription lundi 12 mai 2003 Statut Membre Dernière intervention 8 février 2011
18 mai 2005 à 11:21
Tu doit avoir microsoft DAO 3.6 Objet Library ou plus d'installer en référence
( installer MDAC )

Voici une solution avec une connexion OLE bien plus éfficace que ODBC

----------------- Variables :
Global strProvider As String
Global strNomBase As String
Global strServeur As String
Global strUtilisateur As String
Global strPassword As String
Global pServeur As New ADODB.Connection

global strTable as string

--------------- fonction connexion
Dim strConnexion As String

strProviderFrigo = "SQLOLEDB.1"
strNomBase = "NomTaBase"
strServeur = "NomPosteBD"
strUtilisateur = "sa"
strPassword = ""
strTable = "NomTaTable"

' - Paramètres de connexion
strConnexion = "Persist Security Info=False;"
strConnexion = strConnexion + "User ID=" + strUtilisateur + "; Password=" + strPassword + "; Initial Catalog=" + strNomBase + ";"
strConnexion = strConnexion + "Data Source=" + strServeur

' Création canal de communication avec le serveur SQL
With pServeurFrigo
' - Provider
.Provider = strProvider
' - Chaine de communication
.ConnectionString = strConnexion
' - Différents time-out
.ConnectionTimeout = 6
.CommandTimeout = 60
' - Ouverture connexion
.Open
End With

--------------- fonction déconnexion
Sub FermetureConnect()


' Fermeture de la connexion au serveur
pServeur.Close
Set pServeur = Nothing

--------------- fonction recherche
Sub Recherche()
Dim pRecordSet As New ADODB.Recordset

' Ouverture de la table et recherche
pRecordSet.Open "SELECT * FROM " + strTable + _
"WHERE Piles ='' ORDER By Piles" + _
OBJ_ServeurFrigo, adOpenDynamic, adLockOptimistic

' Si pile trouvée
If pRecordSet.EOF = False Then
' Traitement
' Fermer
pRecordSet.Close
End If
set pRecordSet = nothing

J'espere que ca t'aidera. J'ai fait des copiés coller d'une autre appli mais j'ai pas tester ces lignes ( le principe et bon en tout cas) .
0
Rejoignez-nous