i m using visual studio .net 2003 vc++ mfc i cannot connect to sql server SQLSetEnvAttr() is returning null value everytime i hv used

retcode = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);


pls help !!

Member Avatar for jencas

RTFM (read the fine MSDN): 0 = SQL_SUCCESS

RTFM (read the fine MSDN): 0 = SQL_SUCCESS

===================================

i hv gon through it already it is not working. pls give me the best way to connect to the sql server in vc++

Jencas is trying to tell you that this particulair piece of code is infact working. It returns 0 which indicates succes!
If you have any problems, you should post the rest of the code to.

And this time post your code between code tags: [code=cplusplus] // code here [/code]

[edit]
Whoohoo! my 2k post! :)

Jencas is trying to tell you that this particulair piece of code is infact working. It returns 0 which indicates succes!
If you have any problems, you should post the rest of the code to.

And this time post your code between code tags: [code=cplusplus] // code here [/code]

[edit]
Whoohoo! my 2k post! :)

================================================
pls help me with this code:

void CnewSQLDlg::SqlConnect()
{
   SQLHENV henv;
   SQLHDBC hdbc;
   SQLHSTMT hstmt;
   SQLRETURN retcode;
   SQLPOINTER rgbValue;
   int i = 5;
   rgbValue = &i;

   SQLSMALLINT * OutConnStrLen = (SQLSMALLINT *)malloc(255);

   retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);

  
   if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
   {
     	 retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); 

	
    	 if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
		 {
      		 retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 

			 
        	 if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
		     {
           	    SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)(rgbValue), 0);
          		retcode = SQLConnect(hdbc, (SQLCHAR *)"HIMANSHU-PC", *OutConnStrLen, (SQLCHAR *)"Heman", *OutConnStrLen, (SQLCHAR *)"heman123", *OutConnStrLen);

				
          	 	if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) 
			    {
             		retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 
            		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
				    {
               			SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
             		}
               		SQLDisconnect(hdbc);
         		}
				SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
        	}
     	}
      	SQLFreeHandle(SQL_HANDLE_ENV, henv);
   }
}

pls help me out with this

Where does it fail? And don't tell me "I don't know" because you can very easy put some std::cout's everywhere to see how far the code comes before stopping

Where does it fail? And don't tell me "I don't know" because you can very easy put some std::cout's everywhere to see how far the code comes before stopping

==========================================

its ok thanks..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.