Web Service 使用分布式事务出错(OLE DB provider 'SQLOLEDB'无法启动分布式事务)

 环境 Windows XP SP2 Sql Server 2000

    问题描述 :在搭建 Web Service 时,访问了远程数据库的 Link Server (即应用服务器访问了两台数据库服务器),执行 SQL 语句,如下:
      begin   transaction
    select CNCJ.dbo.Custmoer.TotalVol FROM  CNCJ.dbo.Customer c1 left join OrderHeaderID o1 on c1.OrderID = o1.OrderID  
WHERE or.CustomerProfileID = '188168' and o1.AggType = 'PPV' and o1.OrderMonth = '200805'
    commit   tran  
    go 
   
    CNCJ 为数据库服务器上的 Link Server
 
    出错    
    The operation could not be performed because the OLE DB provider 'SQLOLEDB' was unable to begin a distributed transaction.
    [OLE/DB provider returned message: New transaction cannot enlist in the specified transaction coordinator. ]
    OLE DB error trace [OLE/DB Provider 'SQLOLEDB' ITransactionJoin::JoinTransaction returned 0x8004d00a].
 
   解决办法
  1. 在数据库服务器上打开Sql Server的企业管理器,展开,右键“Local(Windows NT)”属性,确定“自动启动MSTDC”勾上。
  2.  管理工具->组件服务 -> 计算机 -> 我的电脑,右键属性, MSTDC 选项卡,点击按钮“ Security Configuration..” ,勾上 New work DTC Access, Allow Remote Clients 、Allow Remote Administration、Allow Inbound、Allow Outbound、No Authentication Required、Enable Transaction Internet Protocol(TIP) Transactions、Enable XA Transactions,Account:为NT AUTHORITY/Newwork Service
  3. 管理工具->服务->找到Distributed Transaction Coordinator,双击,选择“Log on”选项卡,确保This account为NT AUTHORITY/Network Server。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用OLE DB连接和操作SQL Server Compact 3.5数据库的VC++代码示例: ```cpp #include <windows.h> #include <sqloledb.h> #include <iostream> #include <string> using namespace std; int main() { // 初始化 COM 库 CoInitialize(NULL); // 定义连接字符串(替换为自己的数据库路径和名称) wstring connStr = L"Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\\MyData.sdf;Persist Security Info=False;"; // 创建连接对象 IDBInitialize* pConnection = NULL; HRESULT hr = CoCreateInstance(CLSID_SQLSERVERCE, NULL, CLSCTX_INPROC_SERVER, IID_IDBInitialize, (void**)&pConnection); if (FAILED(hr)) { cout << "连接数据库失败!" << endl; return 0; } // 初始化连接对象 hr = pConnection->Initialize(); if (FAILED(hr)) { cout << "初始化连接对象失败!" << endl; return 0; } // 定义命令字符串 wstring sqlCmd = L"SELECT * FROM MyTable"; // 创建命令对象 ICommandText* pCommand = NULL; hr = pConnection->QueryInterface(IID_ICommandText, (void**)&pCommand); if (FAILED(hr)) { cout << "创建命令对象失败!" << endl; return 0; } // 设置命令文本 hr = pCommand->SetCommandText(DBGUID_DBSQL, sqlCmd.c_str()); if (FAILED(hr)) { cout << "设置命令文本失败!" << endl; return 0; } // 执行命令 IRowset* pRowset = NULL; hr = pCommand->Execute(NULL, IID_IRowset, NULL, NULL, (IUnknown**)&pRowset); if (FAILED(hr)) { cout << "执行命令失败!" << endl; return 0; } // 获取结果集 HROW hRow = NULL; DBCOUNTITEM count = 0; while (pRowset->GetNextRows(NULL, 0, 1, &count, &hRow) == S_OK) { // 获取行数据 DBBINDING binding; DWORD dwBindingSize = sizeof(binding); pRowset->GetBindings(0, &binding, &dwBindingSize); BYTE* pData = new BYTE[binding.cbMaxLen]; pRowset->GetData(hRow, binding.obValue, pData, binding.cbMaxLen); // 处理行数据 // ... // 释放内存 delete[] pData; pData = NULL; // 释放行句柄 pRowset->ReleaseRows(1, &hRow, NULL, NULL, NULL); hRow = NULL; } // 释放结果集 pRowset->Release(); pRowset = NULL; // 释放命令对象 pCommand->Release(); pCommand = NULL; // 释放连接对象 pConnection->Uninitialize(); pConnection->Release(); pConnection = NULL; // 释放 COM 库 CoUninitialize(); return 0; } ``` 注意,要使用此代码,需要在项目属性的“链接器”->“输入”->“附加依赖项”中添加以下库文件: ``` oledb.lib sqlceoledb35.lib ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓梦庄子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值