ODBC : ERROR : LNK 2019

Résolu
forfait3 Messages postés 4 Date d'inscription mardi 23 août 2005 Statut Membre Dernière intervention 25 août 2005 - 23 août 2005 à 17:30
forfait3 Messages postés 4 Date d'inscription mardi 23 août 2005 Statut Membre Dernière intervention 25 août 2005 - 24 août 2005 à 10:53
Bonjour,

je développe une application qui doit se connecter à une base de données sous SQL Server 2000 SP3.
Le développement se fait en C++ sous Visual Studio .Net 2003.
Le MDAC installé est le 2.8 SP1.
OS : Windows 2000 Server SP4.

Mon problème se situ au linkage lors de la compilation :

DBImplementation.obj : error LNK2019: symbole externe non résolu _SQLSetEnvAttr@16 référencé dans la fonction "public: __thiscall CDBImplementation::CDBImplementation(void)" (??0CDBImplementation@@QAE@XZ)
...

<gras>Le code associé est le suivant :

Contenu du fichier DBImplementation.h


#include "Sql.h"


#include "Sqlext.h"


#include "Sqltypes.h"


#include "Odbcss.h"


class CDBImplementation


{


private :


SQLHANDLE henv; // environment handle


SQLHANDLE hconn; // connection handle


CString sDBConnection; // connection string


CString sDriver; // driver (SQL Server)


CString sDatabase; // database name


CString sUserName; // user name


CString sPassword; // password


CString sServerName; // server name


public:


CDBImplementation();


~CDBImplementation();


// Accesseurs


CString getDBConnection() {return sDBConnection;}


void setDBConnection(CString value) {sDBConnection = value;}


CString getUserName() {return sUserName;}


void setUserName(CString value) {sUserName = value;}


CString getPassword() {return sPassword;}


void setPassword(CString value) {sPassword = value;}


CString getServerName() {return sServerName;}


void setServerName(CString value) {sServerName = value;}


// Connection


bool connect();


};


#endif



Contenu du fichier DBImplementation.cpp


#include "StdAfx.h"


#include "DBImplementation.h"


CDBImplementation::CDBImplementation()


{


// Initialiaze ODBC and allocate an environment handle


SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);


// Indicate the application


SQLSetEnvAttr(henv ,SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, 0);


// Allocate an connection handle


SQLAllocHandle(SQL_HANDLE_DBC, henv, &hconn);


// Define the driver


sDriver = "SQL Server";


// Define the database


sDatabase = "GPEP";


// Initialize the attributes


sDBConnection = "";


sUserName = "";


sPassword ="";


sServerName ="";


}


CDBImplementation::~CDBImplementation()


{


// Disconnect from SQL Server and make the connection handle available for a new connection


SQLDisconnect(hconn);


// Free the connection handle


SQLFreeHandle(SQL_HANDLE_DBC, hconn);


// Free the environment handle


SQLFreeHandle(SQL_HANDLE_ENV, henv);


}


bool CDBImplementation::connect()


{


// Define read only acces


SQLSetConnectAttr(hconn, SQL_ATTR_ACCESS_MODE, (SQLPOINTER) SQL_MODE_READ_ONLY, 0);


// Define the connection string


sDBConnection = "DRIVER={"+ sDriver + "}; SERVER=" + sServerName + ";DATABASE=" + sDatabase + ";UID=" + sUserName + ";PWD=" + sPassword +";";


// Use a connection string to connect to SQL Server


SQLRETURN retcd = SQLDriverConnect(hconn, 0, (SQLCHAR*) sDBConnection.GetBuffer(), 1,0, 0, 0, SQL_DRIVER_COMPLETE_REQUIRED);


if (retcd == SQL_SUCCESS)


returntrue;


else


returnfalse;


}


Quelqu'un a t'il une idée pour me sortir de se guêpié ?

Merci.

4 réponses

BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
23 août 2005 à 18:08
propriétés du proj, onglet linker tu ajoutes odbc32.lib

sinon tu mets en haut du fichier:
#pragma comment(lib, "odbc32.lib")

ciao...
BruNews, MVP VC++
3
BruNews Messages postés 21040 Date d'inscription jeudi 23 janvier 2003 Statut Modérateur Dernière intervention 21 août 2019
23 août 2005 à 17:52
tu as bien linké avec odbc32.lib ???

ciao...
BruNews, MVP VC++
0
forfait3 Messages postés 4 Date d'inscription mardi 23 août 2005 Statut Membre Dernière intervention 25 août 2005
23 août 2005 à 18:05
Je pense, mais je ne suis pas sûre d'avoir bien paramétré le projet.

Pourrais tu m'indiquer exactement où et comment linker cette librairie ?

Merci.
0
forfait3 Messages postés 4 Date d'inscription mardi 23 août 2005 Statut Membre Dernière intervention 25 août 2005
24 août 2005 à 10:53
Merci pour tout, c'est ok avec le #pragma.
0
Rejoignez-nous