ADO& VARCHAR [英] ADO & VARCHAR

查看:64
本文介绍了ADO& VARCHAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在返回包含VARCHAR列(adVarChar(n)类型)的记录集时,我们发现使用ADO时出现问题。其他数据类型似乎没问题。



Windows 10 Insider Preview Build 17751,18252

Windows Server 2019 Insider Preview Build 17744




We are seeing problems using ADO when returning record sets that contain VARCHAR columns (adVarChar(n) type). Other data types seem to be OK.

Windows 10 Insider Preview Build 17751, 18252
Windows Server 2019 Insider Preview Build 17744


推荐答案



这是一个示例应用程序(vs2017)这说明了问题。 它在早期系统上运行正常。



// ConsoleApplication1.cpp:使用VS2017构建此文件包含'main'函数。程序执行开始和结束。

//

$
#include" pch.h"

#包括< iostream>

#import" msado15.dll" no_namespace重命名(QUOT; EOF"," adoEOF")implementation_only

的#include<串GT;

的#include< TCHAR.H>

$
int main()

{

    std :: cout<< "你好!\ n";;


       if(FAILED(:: CoInitialize(NULL)))

             返回-1;

      试试
       {

              _RecordsetPtr rs;

              HRESULT HR = rs.CreateInstance(__ uuidof(记录));

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; if(FAILED(hr))

              {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; throw _com_error(hr);
$
              }
              RS->将CursorLocation =为adUseClient;

&NBSP;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;常量_bstr_t形状= QUOT; SHAPE APPEND NEW adVarChar(254)AS SrcDestName英寸;



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; / *

             以下调用适用于Windows 2012R2但在Windows 2019上失败:


             &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;代码= 80040E14

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;代码含义= I

                    &NBSP;源= MSDataShape

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;说明=新列的长度SrcDestName不能为零。

              * / b


              //注意W2019中的调试输出有这个错误:  "传递给C运行时函数的参数无效。" - 在2012R2上运行时不会发出的信号

              rs-> Open(shape,_T(" Provider = MSDataShape; data provider = NONE"),adOpenForwardOnly,adLockOptimistic,adCmdText);

 

  &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; std :: cout<< "成功!\ n";;
       }


       catch(_com_error& e)

       {

              _bstr_t bstrSource(e.Source());

              _bstr_t bstrDescription(e.Description());



             &NBSP; //打印COM错误。  

              printf(" Error \ n");

              printf(" \tCode =%08lx \ n",e.Error());

           &NBSP;&NBSP;&NBSP; printf(" \tCode含义=%s \ n",e.ErrorMessage());
$
           ;&NBSP;&NBSP;&NBSP;的printf(QUOT; \tSource =%s\\\
" ;,(LPCSTR)bstrSource);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; printf(" \tDescription =%s \ n",(LPCSTR)bstrDescription);

       }
      

       :: CoUninitialize();

       std :: cout<< "再见!\ n";;
}

Here is a sample app (vs2017) that illustrates the problem.  It runs fine on earlier systems.

// ConsoleApplication1.cpp : Built using VS2017 This file contains the 'main' function. Program execution begins and ends there.
//

#include "pch.h"
#include <iostream>
#import "msado15.dll" no_namespace rename("EOF", "adoEOF") implementation_only
#include <string>
#include <tchar.h>

int main()
{
    std::cout << "Hello!\n";

       if (FAILED(::CoInitialize(NULL)))
              return -1;
       try
       {
              _RecordsetPtr rs;
              HRESULT hr = rs.CreateInstance(__uuidof(Recordset));
              if (FAILED(hr))
              {
                     throw _com_error(hr);
              }
              rs->CursorLocation = adUseClient;
 
              const _bstr_t shape = "SHAPE APPEND NEW adVarChar(254) AS SrcDestName";

              /*
              The following call works on Windows 2012R2 but fails on Windows 2019 with:
                     Code = 80040e14
                     Code meaning = I
                     Source = MSDataShape
                     Description = Length of NEW column SrcDestName cannot be zero.
              */

              // Note debug output in W2019 has this error:  "Invalid parameter passed to C runtime function." - which is not emitted when running on 2012R2
              rs->Open(shape, _T("Provider=MSDataShape;data provider=NONE"), adOpenForwardOnly, adLockOptimistic, adCmdText);
 
              std::cout << "Success!\n";
       }

       catch (_com_error &e)
       {
              _bstr_t bstrSource(e.Source());
              _bstr_t bstrDescription(e.Description());

              // Print COM errors.  
              printf("Error\n");
              printf("\tCode = %08lx\n", e.Error());
              printf("\tCode meaning = %s\n",e.ErrorMessage());
              printf("\tSource = %s\n", (LPCSTR)bstrSource);
              printf("\tDescription = %s\n", (LPCSTR)bstrDescription);
       }
      
       ::CoUninitialize();
       std::cout << "Goodbye!\n";
}


这篇关于ADO&amp; VARCHAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆