Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2004, 11:33 AM
EricCartman EricCartman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 5 EricCartman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MS Access to SQL Server, using C++ and ODBC

I'm doing a project and have hit a brick wall. We started off using Access for dev and testing and now we want to move to a real DB, MS SQL Server. I imported the DB using the MS SQL Server import/export tool, changed the connect string in the code, but can't seem to access the data from my code. I can see the tables using Query Analyzer tool.

Here's the C++ code. The SQLPrepare statement succeeds but the SQLExecute statement fails.

Code:
void ADB::OpenIt()
{
  UCHAR szUID[10] = "Admin";// User ID buffer
  UCHAR szPasswd[10] = "";// Password buffer
  RETCODE rc;
  int iOut;
  char strOut[256];
  char szDSN[256] = DBConn;
  char lpszDSN[256] = "VV2";
  char lpszUid[256] = "user1";
  char lpszPwd[256] = "userpass";


  m_hEnv = NULL; // Env Handle from SQLAllocEnv()
  m_hDBC = NULL; // Connection handle


  SQLAllocEnv (&m_hEnv);
  // Allocate memory for the connection handle
  SQLAllocConnect (m_hEnv, &m_hDBC);

  rc = SQLConnect(m_hDBC, (SQLCHAR*) lpszDSN, SQL_NTS, (SQLCHAR*) lpszUid, SQL_NTS, (SQLCHAR*) lpszPwd, SQL_NTS );


  if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
    DisplayIt( "ADB:Openit db connection OK" );
  else
    DisplayIt( "ADB:Openit db connection failed" );

}

void ADB::CloseIt()
{
  SQLDisconnect (m_hDBC);
  SQLFreeConnect (m_hDBC);
  SQLFreeEnv (m_hEnv);
}

void ADB::GetIt()
{
  HSTMT hStmt = NULL;// Statement handle
  RETCODE rc;
  SQLINTEGER lenrcvd;// buffer bytes recieved
  UCHAR szSqlStr[256];
  SQLINTEGER idate;
  SQLINTEGER itime;
  SQLCHAR userid[51];
  SQLCHAR password[51];
  int j;
  char emsg[100];

  DisplayIt( "ADB:GetIt entered OK" );

  rc = SQLAllocStmt (m_hDBC, &hStmt);
  sprintf (emsg, "SQLAllocStmt rc is %d", rc);
  DisplayIt(emsg);  // this rc comes back 0  


  strcpy(szSqlStr, "SELECT * from VVAppDB.dbo.Passwords");


  rc = SQLPrepare (hStmt, szSqlStr, sizeof (szSqlStr));
  sprintf (emsg, "SQLPrepare rc is %d", rc);
  DisplayIt(emsg);  // this rc comes back 0  
  
  rc = SQLExecute (hStmt);
  sprintf (emsg, "SQLExecute rc is %d", rc);  
  DisplayIt(emsg);  // this rc comes back -1  

  SQLBindCol (hStmt, 1, SQL_C_CHAR, &userid, sizeof(userid), &lenrcvd);
  SQLBindCol (hStmt, 2, SQL_C_CHAR, &password, sizeof(password), &lenrcvd);

  j = 0;
  while ((rc = SQLFetch(hStmt)) != SQL_NO_DATA)
  {
    strcpy(uid[j], userid);
    strcpy(pw[j], password);
    j++;
  }
  usercnt = j;

  SQLFreeStmt (hStmt, SQL_DROP);

}

Any suggestions?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > MS Access to SQL Server, using C++ and ODBC


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT