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.
Afficher la suite