带有 SQL Server Compact Edition 3.5 的经典 ASP ADODB 在命令参数中不起作用

发布于 2024-09-17 22:14:44 字数 504 浏览 5 评论 0原文

我是 SQL CE 新手。我正在使用经典 ASP 进行编程,使用 ADODB.Connection 连接 SQL CE。我已经创建了表并尝试从 ASP 插入数据。我尝试了3种方式。

  1. 内联插入语句 [例如 INSERT INTO tblName(col1, col2) VALUES(1,2)] (已完成)
  2. 参数化插入语句 [例如 INSERT INTO tblName(Col1) VALUES(?)] (已完成) )。我添加了命令参数并提供了值。
  3. 带有多个参数的参数化插入语句(失败)

我不知道多个参数有什么问题。当 Cmd.Execute 语句运行时,它向我抛出未处理的错误。

“远程过程调用失败且未执行。”

我进行了大量的 Google 搜索以找出问题所在。但没有用。我没有得到任何线索。

请帮我解决这个问题

-Ganesh

I'm new to SQL CE. I'm programming in Classic ASP, connecting the SQL CE using ADODB.Connection. I have created the table and trying to insert data from the ASP. I tried in 3 ways.

  1. The inline insert statement [e.g. INSERT INTO tblName(col1, col2) VALUES(1,2)] (WORKED)
  2. The parameterized insert statement [e.g. INSERT INTO tblName(Col1) VALUES(?)] (WORKED). I added the Command Parameter and supplied the value.
  3. The parameterized insert statement with more than one param ( FAILED)

I dont know what wrong with multiple parameters. It throwing me the unhandled error when the Cmd.Execute statement runs.

"The remote procedure call failed and did not execute."

I did lots of Google to find out the issue. But no use. I didn't get any clues.

Please help me to solve this issue

-Ganesh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱影子 2024-09-24 22:14:44

您是否将 Command 对象的 CommandType 属性设置为 adCmdText ?

cmd.CommandType = adCmdText

我就是这样做的:

dim sql : sql = "insert into tbl(fld1, fld2) values(?, ?)"
dim cmd : set cmd = server.createObject("ADODB.Command")
cmd.ActiveConnection = adodbConnection
cmd.CommandType = adCmdText

set param = cmd.CreateParameter("fld1", adVarWChar, , 20, "value1")
cmd.Parameters.Append param
set param = cmd.CreateParameter("fld2", adVarWChar, , 20, "value2")
cmd.Parameters.Append param

cmd.CommandText = sql
cmd.Execute

have you set the CommandType property of the Command object to adCmdText?

cmd.CommandType = adCmdText

thats how i do this:

dim sql : sql = "insert into tbl(fld1, fld2) values(?, ?)"
dim cmd : set cmd = server.createObject("ADODB.Command")
cmd.ActiveConnection = adodbConnection
cmd.CommandType = adCmdText

set param = cmd.CreateParameter("fld1", adVarWChar, , 20, "value1")
cmd.Parameters.Append param
set param = cmd.CreateParameter("fld2", adVarWChar, , 20, "value2")
cmd.Parameters.Append param

cmd.CommandText = sql
cmd.Execute
摇划花蜜的午后 2024-09-24 22:14:44

我想用我自己的示例代码来补充这个问题,该代码也失败了,所以我也在寻找相同的答案。请注意,此示例是用 C++ 编写的,因此,虽然我不能直接质疑 ulluoink 发布的答案,但 VB 答案对我和(我怀疑)OP 不起作用。

// AdoCe.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#include <ole2.h>
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")

#include <string>

int _tmain(int argc, _TCHAR* argv[])
{
    ::CoInitializeEx(NULL, COINIT_MULTITHREADED);

    _ConnectionPtr pConnection = NULL;
    _CommandPtr pCommand = NULL;
    std::string dbConnStr, sql;

    dbConnStr = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=F:\\sample.sdf;Persist Security Info=False;";

    // this sql insert works
    // sql = "INSERT INTO foo (c1) VALUES (?)";
    // this sql insert fails
    sql = "INSERT INTO foo (c1,c2) VALUES (?,?)";

    try {
        pConnection.CreateInstance(__uuidof(Connection));
        HRESULT hr = pConnection->Open(dbConnStr.c_str(), "", "", adConnectUnspecified);

        pCommand.CreateInstance(__uuidof(Command));
        pCommand->ActiveConnection = _ConnectionPtr(pConnection);
        pCommand->CommandType = adCmdText;
        pCommand->CommandText = sql.c_str();

        _ParameterPtr p1 = NULL;
        // !!! assume that our parameters can always be represented as strings
        // !!! also, CE requires adVarWChar or it generates unknown data type error
        p1 = pCommand->CreateParameter("@p1", adVarWChar, adParamInput, 100, "1");
        pCommand->Parameters->Append(p1);


        _ParameterPtr p2 = NULL, p3 = NULL, p4 = NULL, p5 = NULL;
        p2 = pCommand->CreateParameter("@p2", adVarWChar, adParamInput, 100, "cc1");
        pCommand->Parameters->Append( p2 );
        //p3 = pCommand->CreateParameter("@p3", adVarWChar, adParamInput, 128, "cc2");
        //pCommand->Parameters->Append( p3 );
        //p4 = pCommand->CreateParameter("@p4", adVarWChar, adParamInput, 128, "cc3");
        //pCommand->Parameters->Append( p4 );
        //p5 = pCommand->CreateParameter("@p5", adVarWChar, adParamInput, 128, "cc4");
        //pCommand->Parameters->Append( p5 );

        pCommand->Execute(NULL, NULL, adExecuteNoRecords);

        pConnection->Close();
    }

    catch(_com_error& e)
    {
        _bstr_t e1 = e.Description();
        const TCHAR* e2 = e.ErrorMessage();
        IErrorInfo* e3 = e.ErrorInfo();
    }

    ::CoUninitialize();
    return 0;
}

我希望有人可以提供一个解决方案,或者明确地确认由于某些 ADO/CE 限制它根本无法工作。

I would like to supplement this question with my own sample code, which also fails and so I too am looking for the same answer. Note that this sample is in C++ and so, while I cannot directly dispute the answer posted by ulluoink, a VB answer won't work for me and (I suspect) the OP.

// AdoCe.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#include <ole2.h>
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")

#include <string>

int _tmain(int argc, _TCHAR* argv[])
{
    ::CoInitializeEx(NULL, COINIT_MULTITHREADED);

    _ConnectionPtr pConnection = NULL;
    _CommandPtr pCommand = NULL;
    std::string dbConnStr, sql;

    dbConnStr = "Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=F:\\sample.sdf;Persist Security Info=False;";

    // this sql insert works
    // sql = "INSERT INTO foo (c1) VALUES (?)";
    // this sql insert fails
    sql = "INSERT INTO foo (c1,c2) VALUES (?,?)";

    try {
        pConnection.CreateInstance(__uuidof(Connection));
        HRESULT hr = pConnection->Open(dbConnStr.c_str(), "", "", adConnectUnspecified);

        pCommand.CreateInstance(__uuidof(Command));
        pCommand->ActiveConnection = _ConnectionPtr(pConnection);
        pCommand->CommandType = adCmdText;
        pCommand->CommandText = sql.c_str();

        _ParameterPtr p1 = NULL;
        // !!! assume that our parameters can always be represented as strings
        // !!! also, CE requires adVarWChar or it generates unknown data type error
        p1 = pCommand->CreateParameter("@p1", adVarWChar, adParamInput, 100, "1");
        pCommand->Parameters->Append(p1);


        _ParameterPtr p2 = NULL, p3 = NULL, p4 = NULL, p5 = NULL;
        p2 = pCommand->CreateParameter("@p2", adVarWChar, adParamInput, 100, "cc1");
        pCommand->Parameters->Append( p2 );
        //p3 = pCommand->CreateParameter("@p3", adVarWChar, adParamInput, 128, "cc2");
        //pCommand->Parameters->Append( p3 );
        //p4 = pCommand->CreateParameter("@p4", adVarWChar, adParamInput, 128, "cc3");
        //pCommand->Parameters->Append( p4 );
        //p5 = pCommand->CreateParameter("@p5", adVarWChar, adParamInput, 128, "cc4");
        //pCommand->Parameters->Append( p5 );

        pCommand->Execute(NULL, NULL, adExecuteNoRecords);

        pConnection->Close();
    }

    catch(_com_error& e)
    {
        _bstr_t e1 = e.Description();
        const TCHAR* e2 = e.ErrorMessage();
        IErrorInfo* e3 = e.ErrorInfo();
    }

    ::CoUninitialize();
    return 0;
}

I hope someone can offer a solution, or categorically confirm that it simply won't work because of some ADO/CE limitation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文