C++ 读取ini文件动态链接数据库
config.ini文件内容为:[SYSTEM]REMOTE=192.168.1.11DB=PatrolUSER=saPWD=sa获取这个文件的值的代码:CStringr...
config.ini 文件内容为:
[SYSTEM]
REMOTE=192.168.1.11
DB=Patrol
USER=sa
PWD=sa
获取这个文件的值的代码:
CString remote,db,user,pass;
GetPrivateProfileString("SYSTEM","REMOTE","",remote.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
GetPrivateProfileString("SYSTEM","DB","",db.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
GetPrivateProfileString("SYSTEM","USER","",user.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
GetPrivateProfileString("SYSTEM","PWD","",pass.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
把获取到的 remote,db,user,pass
赋值给:
_bstr_t strConnect = "Provider=SQLOLEDB; Server="+remote+";Database="+db+"; uid="+user+"; pwd="+pass+";";
但是链接数据库出错 报错:
用户'(null)'登陆失败
有知道是什么原因吗 展开
[SYSTEM]
REMOTE=192.168.1.11
DB=Patrol
USER=sa
PWD=sa
获取这个文件的值的代码:
CString remote,db,user,pass;
GetPrivateProfileString("SYSTEM","REMOTE","",remote.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
GetPrivateProfileString("SYSTEM","DB","",db.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
GetPrivateProfileString("SYSTEM","USER","",user.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
GetPrivateProfileString("SYSTEM","PWD","",pass.GetBuffer(MAX_PATH),MAX_PATH,"..\\config.ini");
把获取到的 remote,db,user,pass
赋值给:
_bstr_t strConnect = "Provider=SQLOLEDB; Server="+remote+";Database="+db+"; uid="+user+"; pwd="+pass+";";
但是链接数据库出错 报错:
用户'(null)'登陆失败
有知道是什么原因吗 展开
1个回答
展开全部
_bstr_t strConnect = "Provider=SQLOLEDB; Server="+remote+";Database="+db+"; uid="+user+"; pwd="+pass+";";
建议先在外面使用Cstring strTemp;去格式化连接字符串
如strTemp.Format(_T("Provider=SQLOLEDB; Server=%s;Database=%s; uid=%s; pwd=%s"),remote,db,user,pass);
建议先在外面使用Cstring strTemp;去格式化连接字符串
如strTemp.Format(_T("Provider=SQLOLEDB; Server=%s;Database=%s; uid=%s; pwd=%s"),remote,db,user,pass);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询