关于数据库可以设置用户名,密码的问题

shn521 2011-07-07 05:01:41
例如执行
m_pConnection->Open("Driver={SQL Server};Server=127.0.0.1;DATABASE=shn;UID=shn;PWD=123","","",adModeUnknown);

假设strip,strdata,struid,strpwd

我想在MFC里对Server=127.0.0.1;DATABASE=shn;UID=shn;PWD=123进行设置,就是在编辑框里填写IP等,应该怎么写呢
感谢!

...全文
114 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuohoo 2011-07-09
  • 打赏
  • 举报
回复
你调试看报错信息
shn521 2011-07-09
  • 打赏
  • 举报
回复
CString order;
order.Format("Driver={SQL Server};Server=%s;DATABASE=%s;UID=%s;PWD=%s",strip,strdata,struid,strpsw);
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象

if(SUCCEEDED(hr))
{
m_pConnection->Open(_bstr_t(_T(order)),"","",adModeUnknown);

}
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
::MessageBox(NULL,temp,"提示信息",NULL);
AfxMessageBox(e.Source());
AfxMessageBox(e.Description());
}
m_pRecordset.CreateInstance("ADODB.Recordset");//记录集对象
hr = m_pRecordset->Open("SELECT * FROM test2",_variant_t((IDispatch *)m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
这里错了,好奇怪啊,没改前是好用的
shn521 2011-07-08
  • 打赏
  • 举报
回复
人工置顶
shn521 2011-07-08
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 super_href 的回复:]
你用的是什么数据库啊!!!
[/Quote]
SQL2008
shn521 2011-07-08
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 luciferstar 的回复:]
debug看错在哪里了。
[/Quote]
CString order;
order.Format("Driver={SQL Server};Server=%s;DATABASE=%s;UID=%s;PWD=%s",strip,strdata,struid,strpsw);
HRESULT hr;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象

if(SUCCEEDED(hr))
{
m_pConnection->Open(_bstr_t(_T(order)),"","",adModeUnknown);

}
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("连接数据库错误信息:%s",e.ErrorMessage());
::MessageBox(NULL,temp,"提示信息",NULL);
AfxMessageBox(e.Source());
AfxMessageBox(e.Description());
}
m_pRecordset.CreateInstance("ADODB.Recordset");//记录集对象
hr = m_pRecordset->Open("SELECT * FROM test2",_variant_t((IDispatch *)m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText);
这里错了,好奇怪啊,没改前是好用的
LuciferStar 2011-07-08
  • 打赏
  • 举报
回复
debug看错在哪里了。
super_href 2011-07-08
  • 打赏
  • 举报
回复
你用的是什么数据库啊!!!
shn5217758521 2011-07-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zyq5945 的回复:]
http://blog.csdn.net/zyq5945/archive/2010/05/13/5586423.aspx
[/Quote]
这个没有解决我提出的问题啊
shn521 2011-07-08
  • 打赏
  • 举报
回复
人工置顶
shn521 2011-07-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ouyh12345 的回复:]
CString::Format

假设已经获得的ip等
CString connect_str;
connect_str.Format("Driver={SQL Server};Server=%s;DATABASE=%s;UID=%s;PWD=%s",ip,db,user,pwd);
[/Quote]
m_pConnection->Open((_bstr_t)connect_str,"","",adModeUnknown);
能编译通过,但运行后连接数据库就出错了。。。
ouyh12345 2011-07-07
  • 打赏
  • 举报
回复
CString::Format

假设已经获得的ip等
CString connect_str;
connect_str.Format("Driver={SQL Server};Server=%s;DATABASE=%s;UID=%s;PWD=%s",ip,db,user,pwd);

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧