使用VC6进行ADO编程,使用SQL SERVER 2000+WINDOWS SERVER 2003+VC6

王朝mssql·作者佚名  2006-05-27
窄屏简体版  字體: |||超大  

使用VC6进行ADO编程,使用SQL SERVER 2000+WINDOWS SERVER 2003+VC6

目的是将SERVER产生的日志文件--文本格式,写入到SQL SERVER数据库,实现功能为:

1.修改源日志格式为以跳格键分割字段,字段用引号引起,写入成一个新的日志文件。

2.程序读出新日志文件,写入到数据库。

由于是初学VC,不当之处请高人指正,万分感谢!

第一部分

工程名称为vcado,如下是在vcado.cpp中的重要源代码:此代码目的为打开Connection对象!

BOOL CVcadoApp::InitInstance()

{

AfxEnableControlContainer();

AfxOleInit();///初始化COM库

////////////连接数据库//////////////

HRESULT hr;

try

{

hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象

if(SUCCEEDED(hr))

{

hr = m_pConnection->Open("DSN=test;UID=;PWD=;","","",adModeUnknown);///连接数据库

}

}

}

catch(_com_error e)///捕捉异常

{

CString errormessage;

errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());

AfxMessageBox(errormessage);///显示错误信息

return FALSE;

}

// Standard initialization

// If you are not using these features and wish to reduce the size

// of your final executable, you should remove from the following

// the specific initialization routines you do not need.

#ifdef _AFXDLL

Enable3dControls(); // Call this when using MFC in a shared DLL

#else

Enable3dControlsStatic(); // Call this when linking to MFC statically

#endif

CVcadoDlg dlg;

m_pMainWnd = &dlg;

int nResponse = dlg.DoModal();

if (nResponse == IDOK)

{

// TODO: Place code here to handle when the dialog is

// dismissed with OK

}

else if (nResponse == IDCANCEL)

{

// TODO: Place code here to handle when the dialog is

// dismissed with Cancel

}

// Since the dialog has been closed, return FALSE so that we exit the

// application, rather than start the application's message pump.

return FALSE;

}

int CVcadoApp::ExitInstance()

{

if(m_pConnection->State)

m_pConnection->Close(); ///如果已经打开了连接则关闭它

return CWinApp::ExitInstance();

}

由于本人上网时间问题,下次进行发表“第二部分”。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航