Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:56:37+00:00 2026-06-12T22:56:37+00:00

I am using C++ ODBC to connect to a local SQL Server. Once I

  • 0

I am using C++ ODBC to connect to a local SQL Server.

Once I have attempted to make connecton to the server; Is there a way to validate that the connection was indeed successful?

Here is a sample of my code, which delegates the connection handles and makes the connection:

//Allocate the pre-connection handles
  this->sReturn = SQL_SUCCESS;
  this->sReturn = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &this->eHandle);
  this->sReturn = SQLSetEnvAttr(this->eHandle, SQL_ATTR_ODBC_VERSION, reinterpret_cast<void*>(SQL_OV_ODBC3_80), 4);
  SQLAllocHandle(SQL_HANDLE_DBC, this->eHandle, &this->cHandle);

//Connect to the database
  this->sReturn = SQLConnect(this->cHandle, reinterpret_cast<SQLWCHAR*>(serverName), SQL_NTS, NULL, 0, NULL, 0);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:56:38+00:00Added an answer on June 12, 2026 at 10:56 pm

    According to MSDN, the return values of SQLConnect() are:

    SQL_SUCCESS, SQL_SUCCESS_WITH_INFO, SQL_ERROR, SQL_INVALID_HANDLE, or SQL_STILL_EXECUTING.

    So I’m assuming SQL_SUCCESS or SQL_SUCCESS_WITH_INFO indicate the connection was indeed successful.

    If by “validate”, you mean something other than just looking at the return code, I would imagine any subsequent call using the connection would fail if for some reason the connection were no longer valid.

    Here’s a code example from the same MSDN site – note they check for success OR success with info:

        // Connect to data source
        retcode = SQLConnect(hdbc, (SQLCHAR*) "NorthWind", SQL_NTS, (SQLCHAR*) NULL, 0, NULL, 0);
    
        // Allocate statement handle
        if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
            retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); 
    
           // Process data
           if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) {
              SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
           }
    
           SQLDisconnect(hdbc);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are using a SQL Native Client to connect to a local SQL Server
I am using the ODBC extension in PHP to connect to an SQL 2000
I have an application that originally needed to connect to Sybase (via ODBC), but
I am using ODBC API in c++ to connect to a database. I have
I'm trying to use Perl ODBC to connect to a Microsoft SQL server. My
I have Oracle 11 database to which I connect using both JDBC and ODBC.
I have to connect a Word Document to a SQL Server with VBA in
I have connected sqlserver using ODBC in php. I'm able to connect the database
I'm trying to connect to a local SQL Server 2008 instance from a newly
I am able to successfully connect from access 2007 into SQL Server 2008 using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.