调用SQLDriverConnect总是出错。没法连上。请问谁能简单介绍一下他的语法??
解决方案 »
- 奇怪的问题,我用VC编译OCX程序后,可以打开带这个控件的网页,而同样的OCX,自己注册后,同样的网页却不能打开
- 一道上机题的解法
- 请教:DLL导出类,如何在VC中调用,举个例子!
- 画图工具
- 编程判断系统是否安装SQLServer2000及其他2个问题
- 非模态对话框中莫名其妙的消息流向
- 怎样获得Edit(或者RichEdit)控件的数据的实际存放地址?
- 求救:为什么用send发送CString类型的数据(在一个结构中),接收时接收不到发送的字符串
- 建键表的一个问题:请各位进来,UP有分!
- How to program to open TIFF files
- 半年都没有解决的问题——通过winio取bios密码的程序,最后求救
- #define buffer(x,y) *(pbuffer+y * cxbuffer+x)何解?
unsigned char szDSN[SQL_MAX_DSN_LENGTH+1] = "DBName",
szUID[MAXNAME] = "user",
szAuthStr[MAXNAME] = "pwd"; retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC3,
SQL_IS_INTEGER);
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
retcode = SQLConnect(hdbc1,
szDSN, SQL_NTS,
szUID, SQL_NTS,
szAuthStr, SQL_NTS); if ((retcode != SQL_SUCCESS) &&
(retcode != SQL_SUCCESS_WITH_INFO))
AfxMessageBox("连接数据库错误.");
else
AfxMessageBox("Connection succeed.\n"); retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc1, &hstmt1); CString sqlStr;
CString str;
sqlStr="insert into TEST(ID,NAME) VALUES(1,'45')";
unsigned char *sqlText=(unsigned char *)SqlChr; retcode = SQLPrepare(hstmt1,
sqlText,
SQL_NTS);
retcode = SQLExecute(hstmt1);
if ((retcode != SQL_SUCCESS) &&
(retcode != SQL_SUCCESS_WITH_INFO) )
AfxMessageBox("失败.");
else
AfxMessageBox("成功."); if (pDataBuffer) delete [] pDataBuffer;
SQLFreeHandle(SQL_HANDLE_STMT, hstmt1);
SQLDisconnect(hdbc1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
我用的是driver关键字,还需要dns嘛???
CString strConnection = "Provider=MSDAORA;Data Source=a;User ID=b; Password=c"; try
{
hr =m_pConnection.CreateInstance("ADODB.Connection");
if(SUCCEEDED(hr))
{
hr=m_pConnection->Open((_bstr_t)strConnection,"","",-1);
}
}
catch(_com_error e)
{
// CCommon common;
// AfxMessageBox(common.DisplayAdoError(m_pConnTemp));
AfxMessageBox(e.ErrorMessage());
}
ado连接数据库,不过要注意如果你是客户端,数据源 a 要同客户端配的一致!