谢谢
解决方案 »
- windows程序设计第二版中的"设计自己的线程局部存储"
- 列表控件中,哪个函数可以判断选中的行记录是否为空
- TreeCtrl和Edit联动问题
- 请帮忙看看我这个多线程的程序使用临界区是不是出错了?
- CString s2="select * from xs where name like '%"+m_name+"%'"我测试了一下出现s2的内容是select * from xs where name like '%"+孙+"%
- 出售神龙卡8400 8471等卡OSD源码或组件:
- ★★★有谁使用过IShellChangeNotify接口★★★
- 请问有没有反编译VC++的工具
- 如何判断文件已生成完, 急?
- MFC unicode编码方式下进度条显示不平滑
- WM_QUIT是在程序中的哪里处理的?
- 怎样连接sql-server数据库
CString strTmp;
// CString SQLServerName;
strTmp="driver={sql server};server=199.8.8.8;Database=db;UID=sa;PWD=;");
// Create Connection Object (1.5 Version)
_variant_t vtEmpty (DISP_E_PARAMNOTFOUND, VT_ERROR);
_variant_t vtEmpty2(DISP_E_PARAMNOTFOUND, VT_ERROR);
_bstr_t bstrEmpty(L""); try
{
Conn1.CreateInstance( __uuidof( ADODB::Connection ) );
Conn1->ConnectionString =(LPCTSTR) strTmp;// bstrSQLServerConnect;
Conn1->Open( bstrEmpty, bstrEmpty, bstrEmpty, -1 );
return 0;
}
catch(_com_error & ce)
{
//使用另一种方式登陆
strTmp.Format("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=%s",
DBName);
try
{
Conn1.CreateInstance( __uuidof( ADODB::Connection ) );
Conn1->ConnectionString =(LPCTSTR) strTmp;// bstrSQLServerConnect;
Conn1->Open( bstrEmpty, bstrEmpty, bstrEmpty, -1 );
return 0;
}
catch(_com_error & ce)
{
#ifdef _DEBUG
_bstr_t bstrDescription(ce.Description ());
CString strError;
strError=bstrDescription.copy();
g_pMgr->ShowMsg(99,"Error Code=%s At Line=%4d File=%s",
strError,
__LINE__,
__FILE__ );
#endif }
#ifdef _DEBUG
_bstr_t bstrDescription(ce.Description ());
CString strError;
strError=bstrDescription.copy();
g_pMgr->ShowMsg(99,"Error Code=%s At Line=%4d File=%s",
strError,
__LINE__,
__FILE__ );
#endif
return 1;
}
#include <odbcinst.h>CDatabase m_gDatabase;//the global variable used to link remote database!
void CMainFrame::OnLinkLocalhost()
{
// TODO: Add your command handler code here
RETCODE retcode;
char *szDriver = "SQL Server";
char *szAttributes =
"DSN=DB_DSN\0DESCRIPTION=DSN used for the Visual C++ database test!\0"
"SERVER=199.8.8.8\\your_sqlserver_name\0"//if you have only on sqlserver you can just use the ip
"DATABASE=Db\0";
//first create the data source in localhost://data source is:DB_DSN
retcode = SQLConfigDataSource(NULL,
ODBC_ADD_DSN,
szDriver,
szAttributes);
if(retcode)
MessageBox("Success!");
else
{
MessageBox("Failed");
return;
}
//use the data source :DB_DSN,change the PWD=password to your own passward
if(m_gDatabase.OpenEx( _T( "DSN=DB_DSN;UID=sa;PWD=password" ),
CDatabase::openReadOnly |
CDatabase::noOdbcDialog ))
{
try
{
m_gDatabase.ExecuteSQL(_T(" select * from your_table"));
} catch(CDBException e)
{
MessageBox("Failed to execute the sql commands");
return;
}
}
else
{
MessageBox("Failed to connect the remote database!") ;
return ;
}
}
-----------------------
[email protected]