출처: http://hwanysnote.blogspot.com/2008_03_01_archive.html
Requirements
- MS SQL Server 2005 Express
- MS SQL Server Management Studio Express
- MS VisualStudio 2005 (VC++8)
Instruction
1. Install all Requirements. And Confirm 'MS SQL Server 2005 Express' is running.
2. Execute 'MS SQL Server Management Studio Express'.
3. Add new database.
5. Open ODBC configuration ( Start - Control Panel - Administrative Tools - Data Source )
8. Click Client Configuration
9. Set 'Network Library' to TCP/IP (or other correspond to SQL Server)
10. Check Server's Connection
11. Enabling TCP/IP connection of SQL server.
12. Return to the ODBC configuration and set a default database
( If the connection to the SQL server is valid, the combobox of database names present the
whole database names of the SQL server.)
13. Finally, configuration dialog represent the report.
Click the 'Test Data Source..' if you want.
14. The new Data Souce Name is added.
[Sample Code] Below is the code of connecting ODBC using Win32 C++.
--------------------------------------------------------------------------------------------------
#include <Windows.h>
#include <iostream>
#include <sql.h>
#include <sqlext.h>
int main(int argc, char *argv[])
{
SQLHENV hEnv = NULL;
SQLHDBC hDbc = NULL;
SQLRETURN ret = SQL_SUCCESS;
char ConStr[] = onfuse_p2p_db";
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);
SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3,
SQL_IS_INTEGER);
SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc);
ret = SQLConnect(hDbc,(SQLCHAR *)ConStr, SQL_NTS, (SQLCHAR *)NULL, SQL_NTS,
(SQLCHAR *)NULL, SQL_NTS);
if ((ret != SQL_SUCCESS) && (ret != SQL_SUCCESS_WITH_INFO)) {
std::cout << "Connection:fail" << std::endl;
}
else
{
std::cout << "Connection:success" << std::endl;
}
if (hDbc) SQLDisconnect(hDbc);
if (hDbc) SQLFreeHandle(SQL_HANDLE_DBC, hDbc);
if (hEnv) SQLFreeHandle(SQL_HANDLE_ENV, hEnv);
return 0;
}
--------------------------------------------------------------------------------------------------
'IT_Programming > C · C++' 카테고리의 다른 글
[C++] 스마트 포인터(Smart Pointer) 맛보기 (0) | 2009.09.15 |
---|---|
[펌_C++] SAFE_DELETE 를 template으로 구현! (0) | 2009.08.12 |
[C] 해당경로의 파일만 출력하기 / 하위 디렉토리도 검사 (0) | 2009.07.01 |
[펌] C/C++ 퍼포먼스와 footprint (0) | 2009.06.25 |
[펌] #pragma once 와 #pragma comment() (0) | 2009.06.24 |