DLL C++ 6.0 SQL Server

godonline Messages postés 2 Date d'inscription dimanche 9 mars 2008 Statut Membre Dernière intervention 22 mars 2009 - 21 mars 2009 à 21:57
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 - 22 mars 2009 à 14:02
Bonjour,

J'essaie depuis quelques jours de créer une dll afin de pouvoir alimenter une table de données sous sql server. Je me suis basé à cet effet sur un tutoriel exposé ici http://www.codersource.net/c++_ado_stored_procedure.html
Voici mon code :

#include //This program uses MFC
#include
#include <stdio.h>


#import "C:\Program Files\Fichiers communs\System\ado\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")

int main()
{

/*The following variables will be initialized with necessary values and appended to the strSQL values*/
_bstr_t strName;
_bstr_t strAge;
_bstr_t strDOB;
_bstr_t strSalary;

_ConnectionPtr pConn = NULL;
_CommandPtr pCom;
// Define string variables for connection
_bstr_t strCon("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=user;Password=password;Initial Catalog=MT4TRADE;Data Source=(local);Integrated Security=SSPI;");

HRESULT hr = S_OK;

//Initialize the COM Library
CoInitialize(NULL);

try
{
//Create the Connection pointer
hr = pConn.CreateInstance((__uuidof(Connection)));
if(FAILED(hr))
{
printf("Error instantiating Connection object\n");
goto cleanup;
}

//Open the SQL Server connection
hr = pConn->Open(strCon,"","",0);
if(FAILED(hr))
{
printf("Error Opening Database object\n");
goto cleanup;
}

//Create the C++ ADO Command Object
pCom.CreateInstance(__uuidof(Command));
pCom->ActiveConnection = pConn;

//Make the ADO C++ command object to accept stored procedure
pCom->CommandType = adCmdStoredProc ;

//Tell the name of the Stored Procedure to the command object
pCom->CommandText = _bstr_t("dbo.spTestTable");


//Prepare the Name VARIANT for ADO C++ Command Object Parameter
VARIANT vName;
vName.vt = VT_BSTR; //Variant type for BSTR
vName.bstrVal = _bstr_t("CoderSource C++ ADO Stored Procedure Sample");

//Prepare the Age VARIANT for ADO C++ Command Object Parameter
VARIANT vAge;
vAge.vt = VT_I2; //Variant type for Integer
vAge.intVal = 10;

//Prepare the Salary VARIANT for ADO C++ Command Object Parameter
COleCurrency vOleSalary(5000,55);


//Use COleDateTime class for Date type
COleDateTime vOleDOB( 2004, 2,1 , 0, 0 , 0 ) ;


//Add Parameters to the C++ ADO Command Object
//This adds the string parameter
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("strCompanyName"),adChar,adParamInput,50,vName));
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("iAge"),adInteger,adParamInput,4,vAge));
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("dob"),adDate,adParamInput,8,_variant_t(vOleDOB)));
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("mSalary"),adCurrency,adParamInput,8,_variant_t(vOleSalary)));

_variant_t vNull;
vNull.vt = VT_ERROR;
vNull.scode = DISP_E_PARAMNOTFOUND;

pCom->Execute(NULL,NULL,adCmdStoredProc);

printf("Data Added Successfully\n");
//Close the database
pConn->Close();

}

catch(_com_error & e)
{

_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
printf("\n Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);

}
cleanup:
CoUninitialize();
return 0;
}

En tentant de compiler ce code j'obtiens le code d'erreur suivant :

-------------------Configuration: test - Win32 Debug--------------------
Compiling...
StdAfx.cpp
c:\program files\microsoft visual studio\myprojects\test\debug\msado15.tlh(407) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
c:\program files\microsoft visual studio\vc98\include\comip.h(46) : error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file
Error executing cl.exe.

StdAfx.obj - 1 error(s), 1 warning(s)


Existe t il un moyen simple de résoudre ce problème. Voici encore qq détails :
- Il s'agit d'une MFC Application (dll)
-User et Password remplacent mes véritables login windows pour accéder à ma base de données sql server.
-Je n'ai utilisé dans le code que le fichier .cpp

En espérant que ces détails vous permettront de m'aider.

Cordialement,</stdio.h>

3 réponses

NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
22 mars 2009 à 13:35
Bonjour,

1) ton code est illisible.
2) tu t'es trompé de forum : www.cppfrance.com

http://nhen0039.chez-alice.fr/index.php
0
godonline Messages postés 2 Date d'inscription dimanche 9 mars 2008 Statut Membre Dernière intervention 22 mars 2009
22 mars 2009 à 13:47
Merci je m'en suis rendu compte par la suite je cherche a effacer ce topic mais pas moyen !!
0
NHenry Messages postés 15112 Date d'inscription vendredi 14 mars 2003 Statut Modérateur Dernière intervention 13 avril 2024 159
22 mars 2009 à 14:02
Bonjour,

Tu peux contacter les admins pour supprimer/déplacer cette discussion.

http://nhen0039.chez-alice.fr/index.php
0
Rejoignez-nous