大奇怪啊vc中使用ADO技术连接数据库,Connection象的Open函数丢失连接字串,该怎么处理
大奇怪啊!!vc中使用ADO技术连接数据库,Connection象的Open函数丢失连接字串
在使用ADO访问sql数据库,出现了奇怪的事情.
我用桌面建立.udl文件法获取连接字串,付给了_ConnectionPtr m_pcon-> connectionstring;但是在调试过程中,发现真正传给
inline HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options ) 时,连接字串少了一部分啊!
具体程序如下:
BOOL CMYADO2App::InitInstance()
{
CoInitialize(NULL);
/*m_pcon.CreateInstance(__uuidof(Connection));
m_pcom.CreateInstance(__uuidof(Command));
m_prcd.CreateInstance(__uuidof(Recordset));*/
m_pcon.CreateInstance( "ADODB.Connection ");
m_prcd.CreateInstance( "ADODB.Recordset ");
m_pcon-> ConnectionString= "Provider=SQLOLEDB.1;\
Integrated Security=SSPI;Persist Security Info=False;\
User ID=LOCALWINDOWSNT\\ONE;Initial Catalog=Northwind;\
Data Source=LOCALWINDOWSNT\\ONE ";
CString str=(LPCSTR)m_pcon-> ConnectionString;
m_pcon-> Open((_bstr_t) "Provider=SQLOLEDB.1;\
Integrated Security=SSPI;Persist Security Info=False;\
User ID=LOCALWINDOWSNT\\ONE;Initial Catalog=Northwind;\
Data Source=LOCALWINDOWSNT\\ONE ",
"LOCALWINDOWSNT\\ONE ", " ",\
adConnectUnspecified);
AfxEnableControlContainer();
// 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
CMYADO2Dlg 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;
}
调试到
inline HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options ) 时发现ConnectionString值是
{ "Provider=SQLOLEDB.1; Integrated Security=SSPI;Persist Security Info=False; User ID=LOCALWINDOWSNT\ONE;Initial Catalog=Northwin " (1)}
与原来我给的值相比,Northwind变成了Northwin,Data Source=LOCALWINDOWSNT\\ONE项也丢失了!
结果当然不对了!!
在使用ADO访问sql数据库,出现了奇怪的事情.
我用桌面建立.udl文件法获取连接字串,付给了_ConnectionPtr m_pcon-> connectionstring;但是在调试过程中,发现真正传给
inline HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options ) 时,连接字串少了一部分啊!
具体程序如下:
BOOL CMYADO2App::InitInstance()
{
CoInitialize(NULL);
/*m_pcon.CreateInstance(__uuidof(Connection));
m_pcom.CreateInstance(__uuidof(Command));
m_prcd.CreateInstance(__uuidof(Recordset));*/
m_pcon.CreateInstance( "ADODB.Connection ");
m_prcd.CreateInstance( "ADODB.Recordset ");
m_pcon-> ConnectionString= "Provider=SQLOLEDB.1;\
Integrated Security=SSPI;Persist Security Info=False;\
User ID=LOCALWINDOWSNT\\ONE;Initial Catalog=Northwind;\
Data Source=LOCALWINDOWSNT\\ONE ";
CString str=(LPCSTR)m_pcon-> ConnectionString;
m_pcon-> Open((_bstr_t) "Provider=SQLOLEDB.1;\
Integrated Security=SSPI;Persist Security Info=False;\
User ID=LOCALWINDOWSNT\\ONE;Initial Catalog=Northwind;\
Data Source=LOCALWINDOWSNT\\ONE ",
"LOCALWINDOWSNT\\ONE ", " ",\
adConnectUnspecified);
AfxEnableControlContainer();
// 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
CMYADO2Dlg 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;
}
调试到
inline HRESULT Connection15::Open ( _bstr_t ConnectionString, _bstr_t UserID, _bstr_t Password, long Options ) 时发现ConnectionString值是
{ "Provider=SQLOLEDB.1; Integrated Security=SSPI;Persist Security Info=False; User ID=LOCALWINDOWSNT\ONE;Initial Catalog=Northwin " (1)}
与原来我给的值相比,Northwind变成了Northwin,Data Source=LOCALWINDOWSNT\\ONE项也丢失了!
结果当然不对了!!