VC 연결 MySQL 데이터베이스

3083 단어 VC
참고 글:http://blog.csdn.net/bluemap/article/details/5726355
------------------------------------------------------------------------------------------------------
1. msado15. dll 가 져 오기
#include "stdafx.h" #include "MySQLTest.h" #include "MySQLTestDlg.h" #import "C://program files//common files//system//ado//msado15.dll" no_namespace rename ("EOF", "adoEOF")
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
2. 제어 판 에서 ODBC 관리 자 를 열 고 이 컴퓨터 에 설 치 된 MySQL 드라이버 를 확인 합 니 다. 제 것 은... MySQL ODBC 5.2w Driver
, 다음 과 같이 캡 처:
VC 连接MySQL数据库_第1张图片
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3. MYSQL 데이터 베 이 스 를 연결 하 는 코드 작성:
void CMySQLTestDlg::OnButton1() 
{
	CoInitialize(NULL);                                          //   Com  
	
	_ConnectionPtr conPtr;                                       //       
	
	//conPtr.CreateInstance("ADODB.Connection");            //Connection            
	conPtr.CreateInstance(__uuidof(Connection));            //Connection                 
	
	// MySQL ODBC 5.2w Driver     (      MySql     ),
	//localhost      ,test     
	CString conStr=_T("Driver={MySQL ODBC 5.2w Driver};Server=localhost;Database=test;");
	
	/******************     ********************/
	try
	{
		//root       ,sa   123456
		conPtr->ConnectionTimeout = 5;                          
		conPtr->Open((_bstr_t)conStr, _T("root"),_T("123456"), adModeUnknown);
		AfxMessageBox(_T("  MySQL     "));

		conPtr->Close();
		conPtr.Release();	//  ,        Release()
	}
	catch(_com_error e)    //    	
	{
		
		AfxMessageBox(e.ErrorMessage());	
	}
	
	CoUninitialize();  //  com  
}

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
효과 캡 처:
VC 连接MySQL数据库_第2张图片
---------------------------------------------------------------------------------------------

당신 의 매우 만족 은 내 가 추구 하 는 취지 입 니 다.
당신 의 한 가지 건 의 는 나의 후속 동력 입 니 다.

좋은 웹페이지 즐겨찾기