⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlserver.cpp

📁 VC后台服务的模板框架
💻 CPP
字号:
// SqlServer.cpp: implementation of the SqlServer class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"

#include "SqlServer.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern CString gStr_dsname,gStr_username,gStr_passwd;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SqlServer::SqlServer()
{
	tbl_conn=false;
	dbOpen();
}

SqlServer::~SqlServer()
{
	
	DEBUGINFO("Database Disconnect \n");
	dbClose();
}

//以ODBC方式打开数据库.
void SqlServer::dbOpen()
{
	
		DEBUGINFO("gStr_dsname[%s],gStr_username[%s],gStr_passwd[%s]\n",gStr_dsname,gStr_username,gStr_passwd);
		
		tbl_conn=db.ConnectDB(gStr_dsname,gStr_username,gStr_passwd);
		if(tbl_conn)
		    ::OutputDebugString("\n=======Database Connect  ok!!!=====\n");
		else 
			::OutputDebugString("\n=======Database Connect  fail!!!=====\n");
}

void SqlServer::dbClose()
{
	db.DisConnect();
	tbl_conn=false;

}
void SqlServer::GetDecode(const char InputBuf[], char *OutBuff)
{
	char mTemp[256];

	memset(mTemp,0,256);

	for (unsigned int i=0; i < strlen(InputBuf); i++)
	{
		mTemp[i] = ~InputBuf[i];
	}
	strcpy(OutBuff,mTemp);
}

/*
错误处理
void SqlServer::GenerateError(HRESULT hr, PWSTR pwszDescription)
//void GenerateError(HRESULT hr, PWSTR pwszDescription)
{
	int flag =0;
	try
	{
		CString	strError;
		strError.Format("Run-times error '%d (%x)'",hr,hr);
		strError += "\n";
		strError += pwszDescription;
		unsigned char mErr[10];
		sprintf((LPTSTR)mErr,"%x",hr);
		if (!strcmp((LPCTSTR)mErr , "80004005"))
		{
			flag = 1;
			DbPtr->Close();
			DbPtr.Release();
		//	dbOpen();
		}
		DEBUGINFO((LPCTSTR)strError);
	}
	catch (...)
	{
		
	}
}


*/

CMyODBC SqlServer::GetDb()
{
	return(db);
}

BOOL SqlServer::IsConnected()
{

	return tbl_conn;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -