"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=;PassWord=;Initial Catalog=;Data Source="

本文深入解析了使用OLE DB连接数据库时的关键参数配置,包括Provider、PersistSecurityInfo、UserID、PassWord、InitialCatalog和DataSource,旨在帮助开发者高效地建立数据库连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Provider=SQLOLEDB.1 ------打开数据库用oledb的方式连接
Persist Security Info ----是否保存安全信息
User ID-------------------用户名
PassWord------------------密码
Initial Catalog-----------数据库的名称或者数据库ip或者目录
Data Source---------------数据源
_ConnectionPtr* m_pConnect = new _ConnectionPtr; // 创建连接对象 m_pConnect->CreateInstance(__uuidof(Connection)); string strConnectStr = "Provider=OraOLEDB.Oracle.1;Password=bsoftbsoft;Persist Security Info=True;User ID=bsrun;Data Source=HRP"; //"Provider=SQLOLEDB.1;Password=Kqyy@88063058;Persist Security Info=True;User ID=sa;Initial Catalog=OpenMas;Data Source=168.168.199.11,1433"; try { _bstr_t bstrConnection = strConnectStr.c_str(); if (NULL != *m_pConnect) { (*m_pConnect)->ConnectionString = bstrConnection; (*m_pConnect)->Open("", "", "", NULL); //(*m_pConnect)->Open("Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=hissms", (_bstr_t)"sa", (_bstr_t)"Kqyy@88063058", adModeUnknown); } _RecordsetPtr* pRecordsetTbkk = new _RecordsetPtr; pRecordsetTbkk->CreateInstance(__uuidof(Recordset)); (*pRecordsetTbkk)->CursorLocation = adUseClient;// adUseClient; // 必须在Open前设置:ml-citation{ref="3" data="citationList"} FieldsPtr pFields = (*pRecordsetTbkk)->GetFields(); FieldPtr pField2 = pFields->Append("jjje", adDouble, 8, adFldUnspecified); (*pRecordsetTbkk)->Open("SELECT ZY_TBKK.JKXH,ZY_TBKK.ZYH,ZY_BRRY.ZYHM,ZY_BRRY.BRXM,ZY_BRRY.BRCH,ZY_BRRY.BRKS,ZY_TBKK.JKRQ,'' AS DXJE, ZY_TBKK.JKJE, ZY_TBKK.JKJE as jkje2,ZY_TBKK.JKFS,ZY_TBKK.SJHM,ZY_TBKK.ZPHM,ZY_TBKK.ZFPB,ZY_TBKK.CZGH,ZY_TBKK.JGID,zy_tbkk.cdbz,ZY_BRRY.dmpi,ZY_TBKK.zfrq,ZY_TBKK.zfgh,ZY_TBKK.JKRQ as czrq,ZY_TBKK.cwtk,ZY_TBKK.bqczgh FROM ZY_TBKK left join ZY_BRRY on ZY_TBKK.ZYH = ZY_BRRY.ZYH where ZY_TBKK.ZYH in(select distinct(zyh) from zy_zyjs left join gy_ygdm on zy_zyjs.czgh = gy_ygdm.ygdm where jsrq >= to_date('2025-07-31 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and jsrq <= to_date('2025-07-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss') and (czgh = '0' or '0' = '0')) and ZY_TBKK.JKJE > 0 and (ZY_TBKK.zfpb <> 1 or (ZY_TBKK.zfpb = 1 and ZY_TBKK.zfrq > to_date('2025-07-31 23:59:59', 'yyyy-mm-dd hh24:mi:ss'))) order by zyh, jkxh desc", (*m_pConnect).GetInterfacePtr(), adOpenStatic, adLockOptimistic, adCmdText); double dJkje, dJjje; while (!(*pRecordsetTbkk)->adoBOF) { dJkje = GetJCommonInterface()->getDB_DecimalValue((*pRecordsetTbkk)->GetCollect("jkje")); dJjje = GetJCommonInterface()->getDB_DecimalValue((*pRecordsetTbkk)->GetCollect("jjje")); // 报错 "在对应所需名称或序数的集合中,未找到项目。" _variant_t vTest = (*pRecordsetTbkk)->GetCollect("jkje"); _variant_t vTest2 = (*pRecordsetTbkk)->GetCollect("jjje"); (*pRecordsetTbkk)->PutCollect(_variant_t("jkje"), _variant_t(double(dJkje + dJjje))); DECIMAL decVal; VarDecFromR8(0.0, &decVal); VARIANT varTemp; VariantInit(&varTemp); varTemp.vt = VT_DECIMAL; varTemp.decVal = decVal; _variant_t varValue; varValue.vt = VT_DECIMAL; varValue.Attach(varTemp); (*pRecordsetTbkk)->PutCollect(_variant_t("jkje"), _variant_t(double(0.0))); // 检查字段类型 long jjjeType = (*pRecordsetTbkk)->Fields->Item["jjje"]->Type; // 写入数据 if (jjjeType == adDecimal || jjjeType == adNumeric) { DECIMAL decVal; VarDecFromR8(1.1, &decVal); (*pRecordsetTbkk)->PutCollect(_variant_t("jjje"), _variant_t(decVal)); } else { (*pRecordsetTbkk)->Fields->GetItem("jjje")->PutValue(_variant_t(1.1)); (*pRecordsetTbkk)->Fields->Item["jjje"]->Value = vtMissing; (*pRecordsetTbkk)->Fields->Item["jjje"]->Value = _variant_t(1.1); (*pRecordsetTbkk)->PutCollect(_variant_t("jjje"), _variant_t(double(1.1))); } // (*pRecordsetTbkk)->PutCollect(_variant_t("jjje"), _variant_t(double(1.1))); //(*pRecordsetTbkk)->PutCollect(_variant_t("jkje"), varValue); (*pRecordsetTbkk)->MovePrevious(); } } catch (_com_error &e) { string m_strLastErrorInfo = GetJCommonInterface()->getDBErrorDetail(e); return; }
最新发布
08-14
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值