CString strPath;
GetModuleFileName(NULL,strPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
strPath.ReleaseBuffer();
int nPos;
nPos = strPath.ReverseFind('//');
strPath=strPath.Left(nPos);
char ConfigFile[128];
strcpy(ConfigFile,strPath);
strcat(ConfigFile,"//SqlPz.ini");
if(0 == GetPrivateProfileString("网络配置","SqlServer","",m_strSqlServer.GetBuffer(MAX_PATH),MAX_PATH,ConfigFile))
{
ASSERT("读取SqlServer失败");
return false;
}
if(0 == GetPrivateProfileString("网络配置","DatabaseName","",m_strDatabaseName.GetBuffer(MAX_PATH),MAX_PATH,ConfigFile))
{
ASSERT("读取m_strDatabaseName失败");
return false;
}
if(0 == GetPrivateProfileString("网络配置","UserName","",m_strUserName.GetBuffer(MAX_PATH),MAX_PATH,ConfigFile))
{
ASSERT("读取m_strUserName失败");
return false;
}
if(0 == GetPrivateProfileString("网络配置","Password","",m_strPassword.GetBuffer(MAX_PATH),MAX_PATH,ConfigFile))
{
ASSERT("读取m_strPassword失败");
return false;
}
char strConn[128] ;
strcpy(strConn,"Provider=SQLOLEDB.1; Data Source=");
strcat(strConn,m_strSqlServer);
strcat(strConn,"; Initial Catalog=");
strcat(strConn,m_strDatabaseName);
strcat(strConn,"; User ID=");
strcat(strConn,m_strUserName);
strcat(strConn,"; PWD=");
strcat(strConn,m_strPassword);