I posted this in the C++ section but didn’t get any responses so I thought it might be more appropriate here.
I’m trying to call a stored procedure on my SQL 2008 server with the below code. When I look at the query with the SQL profiler I get the following:
What I expect to get is:
It seems as if the first parameter is stepping on the second. As ‘@Email’ is a remnant of the first. Can someone explain what is going on?
I’m trying to call a stored procedure on my SQL 2008 server with the below code. When I look at the query with the SQL profiler I get the following:
Code:
exec GetUserID @Email='test@email.com',@Password='@Email'
Code:
exec GetUserID @Email='test@email.com',@Password='123456'
Code:
#include "stdafx.h" #import "C:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF", "EndOfFile") int _tmain(int argc, _TCHAR* argv[]) { try { ::CoInitialize(NULL); ADODB::_ConnectionPtr ConnectionPtr = NULL; ADODB::_CommandPtr CommandPtr = NULL; ADODB::_ParameterPtr ParameterPtr = NULL; char ConnectionString[200] = "Provider=SQLNCLI10; Server=IL47WS030501; Database=Demo; Trusted_Connection=yes;"; ConnectionPtr.CreateInstance(__uuidof(ADODB::Connection)); if(ConnectionPtr) { ConnectionPtr->Open(ConnectionString, "", "", 0); } CommandPtr.CreateInstance(__uuidof(ADODB::Command)); if(ConnectionPtr && CommandPtr) { CommandPtr->ActiveConnection = ConnectionPtr; CommandPtr->CommandType = ADODB::adCmdStoredProc; CommandPtr->CommandText = _bstr_t("GetUserID"); CommandPtr->NamedParameters = true; VARIANT vEmail; vEmail.vt = VT_BSTR; vEmail.bstrVal = _bstr_t("test@email.com"); VARIANT vPassword; vPassword.vt = VT_BSTR; vPassword.bstrVal = _bstr_t("123456"); CommandPtr->Parameters->Append(CommandPtr->CreateParameter(_bstr_t("@Email"), ADODB::adVarChar, ADODB::adParamInput, sizeof(vEmail), vEmail)); CommandPtr->Parameters->Append(CommandPtr->CreateParameter(_bstr_t("@Password"), ADODB::adVarChar, ADODB::adParamInput, sizeof(vPassword), vPassword)); ADODB::_RecordsetPtr RecordsetPtr = CommandPtr->Execute(NULL, NULL, ADODB::adCmdStoredProc); } return 0; } catch(...) { } }
Comment