necesito conectarme a base de datos en sql-server en lenguaje c, a traves de ODBC RRS feed

  • Pregunta

  • al tratar de conectarme me manda este error:s

    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <sql.h>
    #include <sqltypes.h>
    #include "sqlext.h"
     * see Retrieving ODBC Diagnostics
     * for a definition of extract_<span class="c02l4chz" id="c02l4chz_4" style="height: 14px;">error</span>().
    /*static void extract_error(
        char *fn,
        SQLHANDLE handle,
        SQLSMALLINT type);*/
    main() {
      SQLHENV env;
      SQLHDBC dbc;
      SQLHSTMT stmt;
      SQLRETURN ret; /* ODBC API return status */
      SQLCHAR outstr[1024];
      SQLSMALLINT outstrlen;
      /* Allocate an environment handle */
      SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
      /* We want ODBC 3 support */
      SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION (void *) SQL_OV_ODBC3, 0);
      /* Allocate a connection handle */
      SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
      /* Connect to the DSN mydsn */
      ret = SQLDriverConnect(dbc, NULL, "DSN=Lacandon;", SQL_NTS,
                 outstr, sizeof(outstr), &outstrlen,
      if (SQL_SUCCEEDED(ret)) {
        printf("Returned connection string was:\n\t%s\n", outstr);
        if (ret == SQL_SUCCESS_WITH_INFO) {
          printf("Driver reported the following diagnostics\n");
          extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
        SQLDisconnect(dbc);     /* disconnect from driver */
      } else {
        fprintf(stderr, "Failed to connect\n");
        extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
      /* free up allocated handles */
      SQLFreeHandle(SQL_HANDLE_DBC, dbc);
      SQLFreeHandle(SQL_HANDLE_ENV, env);



    viernes, 17 de abril de 2015 19:32