Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <afxdb.h>
- #include <stdio.h>
- #include <sql.h>
- #include <sqltypes.h>
- #include <sqlext.h>
- #include <string>
- #include <iostream>
- void extract_error(
- char *fn,
- SQLHANDLE handle,
- SQLSMALLINT type)
- {
- SQLINTEGER i = 0;
- SQLINTEGER native;
- SQLWCHAR state[7];
- SQLWCHAR text[256];
- SQLSMALLINT len;
- SQLRETURN ret;
- fprintf(stderr,
- "\n"
- "The driver reported the following diagnostics whilst running "
- "%s\n\n",
- fn);
- do
- {
- ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
- sizeof(text), &len);
- if (SQL_SUCCEEDED(ret))
- printf("%s:%ld:%ld:%s\n", state, i, native, text);
- } while (ret == SQL_SUCCESS);
- }
- void connectTest(SQLCHAR *conn)
- {
- SQLHANDLE henv;
- SQLRETURN rc;
- SQLHANDLE hconn;
- SQLSMALLINT bufsize = 0;
- SQLINTEGER nativeerror = 0;
- SQLSMALLINT textlen = 0;
- SQLCHAR connStrOut[256];
- SQLCHAR sqlstate[32];
- SQLCHAR message[256];
- rc = SQLAllocEnv(&henv);
- if (rc != SQL_SUCCESS)
- {
- printf("\nSQLAllocEnv call failed.");
- return;
- }
- rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hconn);
- if (rc != SQL_SUCCESS)
- {
- SQLFreeHandle(SQL_HANDLE_ENV, henv);
- printf("\nSQLAllocHandle call failed.");
- return;
- }
- rc = SQLDriverConnectA(hconn, NULL,
- conn, SQL_NTS,
- connStrOut, 256, &bufsize,
- SQL_DRIVER_NOPROMPT);
- if (bufsize != 0)
- {
- printf("Connected successfully.\n");
- SQLDisconnect(hconn);
- }
- else
- {
- rc = SQLGetDiagRecA(SQL_HANDLE_DBC, hconn, 1,
- sqlstate, &nativeerror, message, 256, &textlen);
- printf("SQLDriverConnect failed.\n");
- if (rc != SQL_ERROR)
- printf("%s=%s\n", (CHAR *)sqlstate, (CHAR *)message);
- }
- SQLFreeHandle(SQL_HANDLE_DBC, hconn);
- SQLFreeHandle(SQL_HANDLE_ENV, henv);
- }
- void main()
- {
- connect((SQLCHAR*)"Driver={PostgreSQL};Server=192.168.1.140;Port=5432;Uid = postgres; Database=postgres;Pwd=1234");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement