zoukankan      html  css  js  c++  java
  • ODBC 小例

    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    #include <iostream>
    #include <locale>
    #include <string.h>
    #include <sql.h>
    #include <sqlext.h>
    #include <odbcss.h>

    using namespace std;
    SQLHENV henv = SQL_NULL_HENV; //定义环境句柄
    SQLHDBC hdbc1 = SQL_NULL_HDBC; //定义数据库连接句柄
    SQLHSTMT hstmt1 = SQL_NULL_HSTMT; //定义语句句柄
    int main()
    {
    RETCODE retcode;
    retcode = SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv);
    if (retcode < 0)
    {
    cout << "allocate ODBC Environment handle errors." << endl;
    return -1;
    }
    retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);
    if (retcode < 0)
    {
    cout << "the ODBC is not version3.0 " << endl;
    return -1;
    }
    retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
    if (retcode < 0)
    {
    cout << "allocate ODBC connection handle errors." << endl;
    return -1;
    }

    char* szDSN = "SQLSERVER_ODBC_USER";
    char* szUID = "alision";
    char* szAuthStr = "880206";
    retcode = SQLConnect(hdbc1, (SQLCHAR*)szDSN, (SWORD)strlen(szDSN), (SQLCHAR*)szUID, (SWORD)strlen(szUID), (SQLCHAR*)szAuthStr, (SWORD)strlen(szAuthStr));
    if (retcode < 0)
    {
    cout << "connect to ODBC datasource errors." << endl;
    return -1;
    }
    cout << "connect success!" << endl;
    system("pause");
    }

  • 相关阅读:
    简单状态机
    c语言状态机
    存储公司
    正确跑步
    好好做自己能做的
    I2C学习
    es6 generator函数
    es6 for of 循环
    es6 proxy代理
    es6 Symbol类型
  • 原文地址:https://www.cnblogs.com/liangxiaofeng/p/5866616.html
Copyright © 2011-2022 走看看